[ #456742 ] Failing test case for .*?
Skip Montanaro
skip at pobox.com
Sat Nov 3 05:50:38 EST 2001
Python 2.2b1 (#25, Oct 19 2001, 11:44:52) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> s="""a\nb\n1"""
>>> re.findall("[^\n]+?\d", s)
['a\nb\n1']
I don't know if it's a bug, but there are a couple ways to work around it:
>>> re.findall("[^\n]+?\d", s)
['a\nb\n1']
>>> re.findall("[^\n]*\d", s)
['1']
>>> re.findall("(?:[^\n]+)?(\d)", s)
['1']
Maybe there's some kind of operator precedence issue (the "?" binds more
tightly than the "+") that means you have to wrap the first part of the
pattern in a group.
Are you just demonstrating the problem or can't you use "*" instead of "+?"
for some reason?
--
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/
More information about the Python-list
mailing list