Bug in re module?

Ant antroy at gmail.com
Fri Oct 6 17:49:39 CEST 2006

Look at the following minimal example:

>>> import re
>>> p = re.compile(r"(:?Test) (String)")
>>> m = p.search("This is a Test String OK?")
>>> m.groups()
('Test', 'String')

I would have expected this to produce:


since (:?...) should be a non-capturing group. From the module

    A non-grouping version of regular parentheses. Matches whatever
regular expression is inside the parentheses, but the substring matched
by the group cannot be retrieved after performing a match or referenced
later in the pattern.

More information about the Python-list mailing list