[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: regex question

On Wed, Jun 27, 2001 at 09:51:03AM -0500, charles@lunarmedia.net wrote:
> i'd like to test to see if a variable has two \@ symbols, and i am
> struggling with the best way to do so. i am sure the format of the string
> will be
> foo@bar.com foo@baz.com
> where the empty space between the two addresses could be any one or two
> characters. so far, i have come up with
> /^(\w)+\@(\w)+\.(\w)+(.|..)(\w)+/@/
> but i am not certain if this is very efficient. i only test up to the
> second @ in my regex which i think is sufficient to verify whether or not
> the string has two @ symbols

Couldn't you use something like this:


It *does* work, but I wouldn't swear to any increased efficiency...

echo "moo@moo.com sheep.net" | perl -nle'print if(/^(\w+\@\w+(\.\w+)+\s*){2}/);'
echo "moo@moo.com bah@sheep.net" | perl -nle'print if(/^(\w+\@\w+(\.\w+)+\s*){2}/);'

--Danny, who always screws up regex's on the first try, for some reason :)
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.