re module - Maximum recursion limit exceeded.

Tim Peters tim.one at home.com
Tue May 29 21:37:22 EDT 2001


[Vicente Rey Bakaikoa]
> ...
> >>> re.search('a.*?b','a'+'c'*9997)
> >>> re.search('a.*?b','a'+'c'*9998)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/usr/home/rey/python/lib/python2.1/sre.py", line 57, in search
>     return _compile(pattern, flags).search(string)
> RuntimeError: maximum recursion limit exceeded
>
> I am running Python 2.1 ( released ). This is and 'old' bug
> for which F.Lundh was already proposing a path with 2.02b. I would
> have expected the patch to be included with python 2.1.
>
> Am I missing something?

Nope.  /F is now proposing a patch for 2.2 instead.

not-all-limitations-are-easy-to-remove-ly y'rs  - tim


PS:  In the meantime, play with different ways to approach your problem.
You certainly don't need all the heavy regexp machinery to accomplish what
that specific regexp does; but if you're unreasonably fond of regexps, write
it 'a[^b]*b' instead -- then you can search strings with millions of
characters without problems.  Minimal matches are an inefficient hack best
reserved for searching short strings (like, say, mail headers).





More information about the Python-list mailing list