Marcel Molina Jr.
6/20/2007 11:18:00 PM
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
"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
--
Marcel Molina Jr. <marcel@vernix.org>