regular expression questions in Python

Reinhold Birkenfeld reinhold-birkenfeld-nospam at
Mon Jul 11 17:56:18 CEST 2005

Jeremy wrote:
> 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
                    ^ This space will not be a space in the RE.
                      You have to specify a space with '[ ]' or '\ '
                      when using re.VERBOSE

>                   (.\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


More information about the Python-list mailing list