[lug] regex question

Chip Atkinson catkinson at circadence.com
Wed Jun 27 09:25:30 MDT 2001


It depends what you are actually trying to do.  Another pattern that 
works is  /^[^\@]*\@[^\@]*\@[^\@]*$/  As for efficiency, I can't say 
which is better.
Yet another approach is to use split and split on /\@/ and count the 
number of array elements.  This assumes that you are going to have non-@ 
characters before and after the @.  If that is always true, the number 
of array elements returned is going to be 3.  This is probably not as 
efficient though as it involves a function call as well as a pattern match.
If you are trying to match valid email addresses, that is a much more 
difficult task and is mentioned in the Perl Cookbook which gives a 
reference to O'Reilly's Mastering Regular Expressions.

Chip

charles at 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 at bar.com foo at 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
> 
> is there a better way to do this?
> 
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug




More information about the LUG mailing list