regex question

János janos.lobb at yale.edu
Thu Apr 5 11:44:44 PDT 2007


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.

Milo and Kreme gave some good tips, so for now I go with

>> "^[ACNS][0-9]{2}-[0-9]{1,6}$"

Thanks again,

János





More information about the MacOSX-admin mailing list