regular expression questions in Python

Jeremy jlconlin at
Mon Jul 11 17:45:26 CEST 2005

I am (very) new top regular expressions and I am having a difficult time 
understanding how to do them.  I have the following in my script:

zaidsearch = r'''^ {5,}([\d]{4,5})(.\d{2,2}c)'''
ZAIDSearch = re.compile(search, re.IGNORECASE)

When I do: then this works fine.  I would like to write 
   it as:

zaidsearch = r'''^ {5,}([\d]{4,5})  #My comments
                  (.\d{2,2}c)        #More of my comments'''
ZAIDSearch = re.compile(zaidsearch, re.VERBOSE)

but this doesn't work.  I get the following error:

     raise error, v # invalid expression
sre_constants.error: nothing to repeat

So I guess my question is: how do I use the VERBOSE option to make my 
regular expression easier to understand for a human?  Secondly, how can 
I use both the VERBOSE and IGNORECASE options?

More information about the Python-list mailing list