Regular Expression Non Capturing Grouping Does Not Work.

Virtual Buddha virtualbuddha at gmail.com
Sat Jun 27 03:28:39 EDT 2009


Hello all,

I am having some difficulties with the non-capturing grouping in
python regular expression module.

Even the code from the online documentation (http://docs.python.org/
howto/regex.html#non-capturing-and-named-groups) does not seem to
work.

As per the docs given in the link above this should happen (text
copied from the page):

>>> m = re.match("([abc])+", "abc")
>>> m.groups()
('c',)
>>> m = re.match("(?:[abc])+", "abc")
>>> m.groups()
()

BUT, this is what I get:

>>> m = re.match("([abc])+", "abc")
>>> m.group()
'abc'
>>> m = re.match("(?:[abc])+", "abc")
>>> m.group()
'abc'

I am using python 2.6 on opensuse 11.1. Any one know what I might be
doing wrong? Or is this a bug?

Thank you
VB





More information about the Python-list mailing list