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/