Regexp syntax change in 1.6?
Adam Sampson
azz at gnu.org
Thu Sep 7 09:52:10 EDT 2000
Hiya.
Under Python 1.5.2, I had a script containing the following line:
m = re.match(r"[a-z0-9]*://[^/]+/.*\.([^.#\?/]*)([#\?]?.*)?", url)
(Bonus points for guessing what it does; answer down the bottom.)
Under 1.6, this fails with:
[...]
File "/usr/local/lib/python1.6/sre.py", line 44, in match
return _compile(pattern, flags).match(string)
File "/usr/local/lib/python1.6/sre.py", line 102, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat
I can narrow it down to:
>>> import re
>>> m = re.match(r"(x?)?", url)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python1.6/sre.py", line 44, in match
return _compile(pattern, flags).match(string)
File "/usr/local/lib/python1.6/sre.py", line 102, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat
whereas:
>>> m = re.match(r"(x?.)?", url)
works fine. Is this correct behaviour for SRE, or am I just being stupid?
"(x?)?" looks like a perfectly reasonable Perl-style regexp to me (and Perl
too)...
[Same question sent to python-help, before I remembered that my Usenet
connection actually works now.]
--
Adam Sampson
azz at gnu.org
[ The regexp extracts the extension of the file specified in a URL. ]
More information about the Python-list
mailing list