Iterate over group names in a regex match?

Brian D briandenzer at
Tue Jan 19 18:14:29 CET 2010

Here's a simple named group matching pattern:

>>> s = "1,2,3"
>>> p = re.compile(r"(?P<one>\d),(?P<two>\d),(?P<three>\d)")
>>> m = re.match(p, s)
>>> m
<_sre.SRE_Match object at 0x011BE610>
>>> print m.groups()
('1', '2', '3')

Is it possible to call the group names, so that I can iterate over

The result I'm looking for would be:

('one', 'two', 'three')

More information about the Python-list mailing list