Possible 2.0b2 bug: Recursion limit in non-greedy regular expressions

Richie Hindle richie at entrian.com
Fri Sep 29 14:50:30 EDT 2000


Hi,

2.0b2's sre module seems to have a problem with non-greedy matching in
longish strings.  If I run the following code in 2.0b2:

>>> re.match( 'a.*?b', 'a' + 'c' * 16167 )

it fails with "RuntimeError: maximum recursion limit exceeded".
Decreasing the number of 'c's to 16166 makes it OK.

In 1.52, I can happily say:

>>> re.match( 'a.*?b', 'a' + 'c' * 100000000 )  # One hundred million 'c's

and it works like a charm, albeit a slow and memory-hungry one.

Here's the full session, with platform details and so on:

> D:\Python20>python
> Python 2.0b2 (#6, Sep 26 2000, 14:59:21) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> >>> import re
> >>> re.match( 'a.*?b', 'a' + 'c' * 16167 )
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "D:\Python20\lib\sre.py", line 44, in match
>     return _compile(pattern, flags).match(string)
> RuntimeError: maximum recursion limit exceeded

Have I missed something, or is this a bug?  Or both?  8-)

-- 
Richie Hindle
richie at entrian.com
Zen buddhist to hot-dog seller: "Make me one with everything"




More information about the Python-list mailing list