regex in python

gisleyt gisleyt at gmail.com
Thu May 25 05:58:17 EDT 2006


I'm trying to compile a perfectly valid regex, but get the error
message:

 r =
re.compile(r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.3/sre.py", line 179, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python2.3/sre.py", line 230, in _compile
    raise error, v # invalid expression
sre_constants.error: nothing to repeat
>>>

What does this mean? I know that the regex
([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*
is valid because i'm able to use it in Regex Coach. But is Python's
regex syntax different that an ordinary syntax?

By the way, i'm using it to normalise strings like:

London|country/uk/region/europe/geocoord/32.3244,42,1221244
to:
London|country/uk/region/europe/geocoord/32.32,42,12

By using \1\2\4 as replace. I'm open for other suggestions to achieve
this!


-Gisle-




More information about the Python-list mailing list