RE bug in Python 2.0b1

Tim Peters tim_one at email.msn.com
Mon Sep 18 00:38:40 EDT 2000


[vio]
> I believe there may be a RE bug in 2.0b1. Consider the following script:
>
> #!/usr/bin/env python
> import re
> s = "red green blue"
> m = re.compile(r'green (\w+)', re.IGNORECASE)
> t = re.subn(m, r'matchedword \1 blah', s)
> print t
>
>
> When I run this on 1.5.2, I get the following expected output:
>
> ('red matchedword blue blah', 1)
>
>
> If I run it on 2.0b1, python basically hangs.

Believe it or not, the thing parsing the replacement string is hung in an
infinite loop trying to get beyond the \1 (!).  Greg Ward just reported a
similar bug on SourceForge (bugs will get noticed much faster if you enter
them there yourself, btw), and a fix will be checked in shortly.  Here's
with a fixed version:

C:\Code\python\dist\src\PCbuild>python
Python 2.0b1 (#5, Sep 17 2000, 10:24:34) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import re
>>> s = "red green blue"
>>> m = re.compile(r'green (\w+)', re.IGNORECASE)
>>> t = re.subn(m, r'matchedword \1 blah', s)
>>> print t
('red matchedword blue blah', 1)
>>>





More information about the Python-list mailing list