problem with regular expression?

Jeff Epler jepler at unpythonic.net
Sat May 15 09:03:50 EDT 2004


I get similar behavior with a slightly simpler program on my system.

$ cat /tmp/kbaum.py
import re
pat = re.compile(r'(a)?(b)')
hay = "a b"
m = pat.search(hay)
if m:
    print m.groups()
    print [m.span(i) for i in range(3)]


$ python2.2 /tmp/kbaum.py
('a', 'b')
[(2, 3), (0, 1), (2, 3)]

$ python2.3 /tmp/kbaum.py
(None, 'b')
[(2, 3), (-1, -1), (2, 3)]

I tested on these versions:
2.2.2 (RedHat 9):          Buggy
2.2.3 (Fedora Core 1):     Buggy
2.3.2 (RedHat 9):          Correct
2.3.4 CVS (Fedora Core 1): Correct

so this bug has been fixed in newer versions of Python, at least for my
simplified regular expression.  If it's been fixed for the expression
you're using, then you should upgrade if you can.  Otherwise, you should
create a bug report on http://sourceforge.net/projects/python/ with the
expression that still doesn't work.

Jeff




More information about the Python-list mailing list