Help with regex

alex23 wuwei23 at gmail.com
Thu Aug 6 12:07:51 EDT 2009


On Aug 7, 1:35 am, Robert Dailey <rcdai... at gmail.com> 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 1,45,10082,3

Would it be easier to do it without regex? The following is untested
but I would probably do it more like this:

TOKEN = 'FILEVERSION '
for line in file:
  if line.startswith(TOKEN):
    version = line[len(TOKEN):]
    maj, min, rev, other = version.split(',')
    break # if there's only one occurance, otherwise do stuff here



More information about the Python-list mailing list