regex in python

Tim Chase python.list at tim.thechases.com
Thu May 25 07:54:44 EDT 2006


>  r =
> re.compile(r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*')
...
> sre_constants.error: nothing to repeat

The error gives something away (like any good error message should)

You're attempting to repeat something that may not exist.  In 
this case, it's the last question-mark.  The item before it

	(\d*)

could be empty, and thus have "nothing to repeat".

Simply removing the question-mark in question, making it

r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*).*'

has the same effect as desired (AFAIU) without the error.

-tkc






More information about the Python-list mailing list