regular expression questions in Python

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
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: ZAID.search(...) 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


Reinhold



More information about the Python-list mailing list