From: Mat Schaffer Date: 2007-01-04T21:07:32+09:00 Subject: Re: scan string w regex .. and HNYTAOY ! On Jan 4, 2007, at 6:55 AM, Josselin wrote: > On 2007-01-04 12:47:06 +0100, Josselin said: > >> HNYTAOY (Dry version of ... Happy New Year To All Of You) >> I am trying to get an array of email addresses from a string , as >> this string is coming from an input textarea in a from, even if I >> ask for a blank between each address, users will also enter some >> return characters... >> so I get something like : >> to_string = "mister.sunnyday@acme.com\r\nmrs_applewhite@eden.com\r >> \njohn_doe@nowhere.com amy-millard@heavencanwait.com" >> I know how to use a_string.scan(" "), but here I should use a >> regex.. after many try .. could not find the correct one.. >> could someone make 2007 starting on right tracks.... thanks a lot !! >> joss > > forgot to mention what I wwrote until now : > >> to_string.split(%r{\r\n\s*}) which gives me teh addresses >> separated by \r\n , but I missed the addresses separated by spaces I would just scan for email addresses. I got this: to_string.scan(/[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i) From this site: http://www.regular-expressions.info/email.html Which seems to do the job reasonably well. Happy new year to you too! -Mat