J_mp
(J. mp)
20 June 2007 23:10
1
WTF:
str = "teste@test.com , alf@test.com , joe@teste.com "
emails_array = Array.new
emails = str.split(",")
emails.each do |single_str|
tmp = single_str[/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i]
if !tmp.nil?
emails_array << tmp
end
end
--- Expected result
emails_array => ["teste@test.com","alf@test.com","joe@teste.com"]
-----Actual result
emails_array => [teste@test.com]
Can't understand
···
--
Posted via http://www.ruby-forum.com/ .
There's a space after each comma in str that the regexp does not allow. Either remove them or split by /\s*,\s*/.
-- fxn
···
On Jun 21, 2007, at 1:10 AM, J. mp wrote:
str = "teste@test.com, alf@test.com, joe@teste.com"
emails_array = Array.new
emails = str.split(",")
emails.each do |single_str|
tmp = single_str[/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i]
"teste@test.com, alf@test.com, joe@teste.com".split(',')
=> ["teste@test.com", " alf@test.com", " joe@teste.com"]
Notice the white space at the start of all but the first email address.
With that whitespace there, the /^ in your regex won't be satisfied.
You probably want do split more like this:
"teste@test.com, alf@test.com, joe@teste.com".split(/\s*,\s*/)
=> ["teste@test.com", "alf@test.com", "joe@teste.com"]
marcel
···
On Thu, Jun 21, 2007 at 08:10:33AM +0900, J. mp wrote:
WTF:
str = "teste@test.com, alf@test.com, joe@teste.com"
emails_array = Array.new
emails = str.split(",")
emails.each do |single_str|
tmp = single_str[/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i]
if !tmp.nil?
emails_array << tmp
end
end
--
Marcel Molina Jr. <marcel@vernix.org>