[ python-Bugs-214033 ] re incompatibility in sre
SourceForge.net
noreply at sourceforge.net
Tue Apr 11 01:11:56 CEST 2006
Bugs item #214033, was opened at 2000-09-11 08:24
Message generated for change (Settings changed) made by tmick
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=214033&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Extension Modules
Group: None
Status: Open
>Resolution: Accepted
Priority: 5
Submitted By: Martin v. Löwis (loewis)
Assigned to: Fredrik Lundh (effbot)
Summary: re incompatibility in sre
Initial Comment:
[submitted by Adam Sampson]
Under Python 1.5.2, I had a script containing the following line:
m = re.match(r"[a-z0-9]*://[^/]+/.*\.([^.#\?/]*)([#\?]?.*)?", url)
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:
>>> 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)...
----------------------------------------------------------------------
Comment By: Trent Mick (tmick)
Date: 2006-04-10 23:11
Message:
Logged In: YES
user_id=34892
I've run into another incarnation of this (it breaks in
Python 2.3.5 and Python 2.4.3):
>>> import sre
>>> sre.compile("(a*)?")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Python24\Lib\sre.py", line 180, in compile
return _compile(pattern, flags)
File "C:\Python24\Lib\sre.py", line 227, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat
Now granted that the '?' here is redundant for the '*'
quantifier on 'a', but compiling this regex works with
Python 2.3's "pre" and it works in Perl.
The actual use case I've hit here is trying to compile all
the regex's in Fedora Core 5's SELinux config files
(/etc/selinux/targeted/contexts/files/file_contexts*). The
first such regex that broke was:
'/usr/share/selinux-policy([^/]*)?/html(/.*)?'
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2000-10-01 18:13
Message:
Yes, it is still broken in 2.0b2.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2000-10-01 04:33
Message:
Martin, is this still broken in 2.0? Fredrik, any idea?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=214033&group_id=5470
More information about the Python-bugs-list
mailing list