[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

scan string w regex .. and HNYTAOY !

Josselin

1/4/2007 11:47:00 AM

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

19 Answers

Josselin

1/4/2007 11:54:00 AM

0

On 2007-01-04 12:47:06 +0100, Josselin <josselin@wanadoo.fr> 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

Mat Schaffer

1/4/2007 12:08:00 PM

0


On Jan 4, 2007, at 6:55 AM, Josselin wrote:

> On 2007-01-04 12:47:06 +0100, Josselin <josselin@wanadoo.fr> 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/...

Which seems to do the job reasonably well.
Happy new year to you too!
-Mat

Josselin

1/4/2007 12:32:00 PM

0

On 2007-01-04 13:07:32 +0100, Mat Schaffer <schapht@gmail.com> said:

>
> On Jan 4, 2007, at 6:55 AM, Josselin wrote:
>
>> On 2007-01-04 12:47:06 +0100, Josselin <josselin@wanadoo.fr> 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/...
>
> Which seems to do the job reasonably well.
> Happy new year to you too!
> -Mat

thanks Mat... I got it too.. my concern is getting all adresses in one array...
It seems that I could do a scan first to replace the \r\n by a space
then doing a split on space character will give me the array
finally I'll use the regex to chexk each email address ( I am using a
Rails plugin validates_as_email , based on RFC2822 with a possibility
to perform an online checking if needed)

Joss

Robert Klemme

1/4/2007 12:35:00 PM

0

On 04.01.2007 13:07, Mat Schaffer wrote:
> On Jan 4, 2007, at 6:55 AM, Josselin wrote:
>> 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.

Yeah, that's what I'd also prefer over splitting.

> 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/...
>
> Which seems to do the job reasonably well.

Hm, IMHO the domain part could be a bit better with respect to dots.
Something like

(?:[A-Z0-9-]+\.)+[A-Z]{2,4}

In some circumstances something simple like this will even work

[^\s@]+@[^\s@]+

And I bet there is a ton of variants...

Cheers

robert

James Gray

1/4/2007 1:06:00 PM

0

On Jan 4, 2007, at 5:55 AM, Josselin wrote:

> 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

You can split() on any whitespace characters with:

to_string.split

That seems easier than a regex to match an email.

James Edward Gray II

Mat Schaffer

1/4/2007 1:45:00 PM

0


On Jan 4, 2007, at 8:06 AM, James Edward Gray II wrote:

> On Jan 4, 2007, at 5:55 AM, Josselin wrote:
>
>> 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
>
> You can split() on any whitespace characters with:
>
> to_string.split
>
> That seems easier than a regex to match an email.

/me slaps his forehead

agreed....
-Mat

jt

3/12/2012 4:13:00 PM

0

On Mon, 12 Mar 2012 10:17:29 -0500, "Ken from Chicago"
<kwicker1b_nospam@comcast.net> wrote:

>> Q. Is the "Walker disease" evolving? I mean, it seems like they are
>> finding "Walkers" who have no bite or scratch marks. It would seem that
>> now every one who dies or is killed quickly comes back as a "Walker".
>
>Yes.

If it's following the comic it's based on, everyone is carrying the virus.
They've already changed some things though so we don't really know for sure
at this point. They just assumed the virus was only passed on from bites
or scratches.

rwgibson13

3/12/2012 4:20:00 PM

0

On Monday, March 12, 2012 11:12:56 AM UTC-5, EGK wrote:
> On Mon, 12 Mar 2012 10:17:29 -0500, "Ken from Chicago"
> <kwicker1b_nospam@comcast.net> wrote:
>
> >> Q. Is the "Walker disease" evolving? I mean, it seems like they are
> >> finding "Walkers" who have no bite or scratch marks. It would seem that
> >> now every one who dies or is killed quickly comes back as a "Walker".
> >
> >Yes.
>
> If it's following the comic it's based on, everyone is carrying the virus.
> They've already changed some things though so we don't really know for sure
> at this point. They just assumed the virus was only passed on from bites
> or scratches.

heh, one hellava virus.
Not only does it raise the dead automatically, but it lowers the IQ of the living and gets rid of that "common sense" thing :-)

RWG (putting carriage returns in to see if I can fix the Google Groups formatting issue)

Mason Barge

3/12/2012 9:01:00 PM

0

On Mon, 12 Mar 2012 10:17:29 -0500, "Ken from Chicago"
<kwicker1b_nospam@comcast.net> wrote:

>"Irish Mike" <ad7cb8d@webnntp.invalid> wrote in message
>news:l69139xlal.ln2@app-01.ezprovider.com...
[...]
>
>I was thinking same, altho it would cool of Merle was NOT the leader of
>Randall's group--because there was someone BADDER than Merle in charge.
>Daryl and Merle could play on brotherly ties to lure each other from the
>opposing groups.

OMG. T-Bag is coming to AMC?

Mason Barge

3/12/2012 9:02:00 PM

0

On Mon, 12 Mar 2012 11:55:09 -0400, Ubiquitous <weberm@polaris.net> wrote:

>In article <jjl42a$8nq$1@dont-email.me>, kwicker1b_nospam@comcast.net wrote:
>>"Irish Mike" <ad7cb8d@webnntp.invalid> wrote:
>
>>> Mean while, back at the ranch (er farm) Lori will continue to do stupid
>>
>>It would be wicked cool if Lori DELIBERATELY set Shane up to think he had a
>>chance so he'd do something stupid and so Rick would be forced to kill him.
>
>Did it seem like perhaps Shane wanted to be killed by Rick and was forcing
>him into the circumstances?

Did you watch "Talking Dead" or something.

I'm not half as impressed with this idea as that lightweight moderator.