re module - error with non-greedy matches

Darrell dgallion1 at yahoo.com
Fri Jan 11 18:57:23 CET 2002


non-greedy can fail as you've seen, when using a large buffer.

>>> import pre, re
>>> buf='x'+'y'*10000
>>> re.search("x.*?x",buf)
>>> pre.search("x.*?x",buf)
>>> buf='x'+'y'*100000
>>> pre.search("x.*?x",buf)
>>> re.search("x.*?x",buf)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "c:\python22\lib\sre.py", line 137, in search
    return _compile(pattern, flags).search(string)
RuntimeError: maximum recursion limit exceeded


pre is the older engine and sre is the new one.
re.py has this:
     engine = "sre"
   # engine = "pre"

sre is faster in many cases.
There is a fix in the works for sre, but it won't be out for a while.
(I can't find the note about that)

--Darrell

Derek Thomson <derekt at dstc.qut.edu.au> wrote in message news:<3C3D381F.2030907 at dstc.qut.edu.au>...
> 
> I'm sure this works, but I really need to know that Python regexes 
> aren't broken before I can seriously use Python for all my scripting 
> needs.



More information about the Python-list mailing list