Problem with SRE's regular expressions
Christophe Delord
christophe.delord at free.fr
Mon Mar 4 15:15:02 EST 2002
Hello,
I'm using regular expressions in python in a parser generator. I have
some troubles with the module named 're'. In fact it uses the 'sre'
module. When I explicitly use the old 'pre' module it works fine.
So my problem is when big strings are scanned using non greedy operator
(for example ".*?") 'sre' seems to be recursivle and python stack limit
is exceeded. With 'pre', their is no problem. Let's consider the
following program (I'm using Python 2.2):
import sre, pre
big_string = "<" + "that's a very very big string!"*1000 + ">"
for re in (pre, sre):
print "testing", re
if re.match('<.*?>', big_string):
print "Ok, it works"
else:
print "Their's a problem here"
This displays :
[christ at localhost py]$ bug_re.py
testing <module 'pre' from '/usr/local/python22/lib/python2.2/pre.pyc'>
Ok, it works
testing <module 'sre' from '/usr/local/python22/lib/python2.2/sre.pyc'>
Traceback (most recent call last):
File "./bug_re.py", line 9, in ?
if re.match('<.*?>', big_string):
File "/usr/local/python22/lib/python2.2/sre.py", line 132, in match
return _compile(pattern, flags).match(string)
RuntimeError: maximum recursion limit exceeded
[christ at localhost py]$
Is this a bug in 'sre' or just a known restriction. I've tried to send a
mail to sre's author (Fredrik Lundh) but his email address seems not to
work. Does anyone know if this behaviour is known and if something is
planned to correct it?
Best regards,
Christophe.
--
Christophe Delord
http://christophe.delord.free.fr/
More information about the Python-list
mailing list