[ #456742 ] Failing test case for .*?

Skip Montanaro skip at pobox.com
Sat Nov 3 11:50:38 CET 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)

I don't know if it's a bug, but there are a couple ways to work around it:

    >>> re.findall("[^\n]+?\d", s)
    >>> re.findall("[^\n]*\d", s)
    >>> re.findall("(?:[^\n]+)?(\d)", s)

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)

More information about the Python-list mailing list