On 06/08/09 08:35, Robert Dailey wrote: > Hey guys, > > 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]+' ) > > This works, but I was hoping for something a bit cleaner. I'm having > to create a special case portion of the regex for the last of the 4 > numbers simply because it doesn't end with a comma like the first 3. > Is there a better, more compact, way to write this regex? > -- > http://mail.python.org/mailman/listinfo/python-list >
Since there cannot be more than one "end of string" you can try this expression: re.compile( r'FILEVERSION (?:[0-9]+(,|$)){4}' ) -- http://mail.python.org/mailman/listinfo/python-list