regex question

Dan Shoop shoop at iwiring.net
Thu Apr 5 14:16:03 PDT 2007


At 2:44 PM -0400 4/5/07, János wrote:
>On Apr 5, 2007, at 1:38 PM, Dan Shoop wrote:
>
>>At 11:31 AM -0400 4/5/07, János wrote:
>>>I need to match some strings that must start 
>>>with any of 'S', 'A', 'C' or 'N', followed by 
>>>two digits followed by a '-' /dash/, followed 
>>>by one to six digits.
>>>
>>>So I created the following one:
>>>
>>>"^[ACNS][0-9]{2}-[0-9]+$"
>>>
>>>I am not so sure that it really fixes the dash 
>>>to the 4th position and it definitely would 
>>>allow more than 6 digits at the end.
>>
>>Regular expressions might be regular but not 
>>exactly all the same. For instance PERL has 
>>it's own schema for regular exxpressions 
>>different from, say, grep.
>>
>>The above looks like a PERL expression, but 
>>probably won't work as expected in grep.
>>
>>What regular expression tool are you using? 
>>Have you tried matching w/o the ^ and %?
>>
>>How about [SACN]\d{1,2}-\d {1,6}
>>--
>
>I don't know.   I am a little green turtle when 
>it comes to regex  or pattern matching :)
>
>Official words /from the developer/ say that it 
>should be an extended regular expression, but I 
>am finding out that for example the [:alpha:] 
>class I wanted to use to replace the bad looking 
>[ACNS] section did not work with the compiled 
>library provided.

Find out which regex library they are using. For 
the expression you had posted you probably want 
the pcre library.

>Milo and Kreme gave some good tips, so for now I go with
>
>>>"^[ACNS][0-9]{2}-[0-9]{1,6}$"

If your lib supports $, and I think that should 
be "^[ACNS][0-9]{2}-[0-9]{1,6}.*$" is you want to 
accept lines with stuff at the ends.
-- 

-dhan

------------------------------------------------------------------------
Dan Shoop                                                   AIM: iWiring
Systems & Networks Architect                      http://www.ustsvs.com/
shoop at iwiring.net                                http://www.iwiring.net/
1-714-363-1174

"The wise man doesn't give the right answers, he poses the right
questions." -- Claude Levi-Strauss

------------------------------------------------------------------------

iWiring provides systems and networks support for Mac OS X, unix, and
Open Source application technologies at affordable rates.


More information about the MacOSX-admin mailing list