Help with regex

Ethan Furman ethan at stoneleaf.us
Thu Aug 6 17:23:47 EDT 2009


Nobody wrote:
> On Thu, 06 Aug 2009 08:35:57 -0700, Robert Dailey wrote:
> 
> 
>>I'm creating a python script that is going to try to search a text
>>file for any text that matches my regular expression. The thing it is
>>looking for is:
>>
>>FILEVERSION #,#,#,#
>>
>>The # symbol represents any number that can be any length 1 or
>>greater. Example:
>>
>>FILEVERSION 1,45,10082,3
>>
>>The regex should only match the exact above. So far here's what I have
>>come up with:
>>
>>re.compile( r'FILEVERSION (?:[0-9]+\,){3}[0-9]+' )
> 
> 
> [0-9]+ allows any number of leading zeros, which is sometimes undesirable.
> Using:
> 
> 	(0|[1-9][0-9]*)
> 
> is more robust.

You make a good point about possibly being undesirable, but I question 
the assertion that your solution is /more robust/.  If the OP 
wants/needs to match numbers even with leading zeroes your /more robust/ 
version fails.

~Ethan~




More information about the Python-list mailing list