How to find out which named regular expression group corresponds to which positional regex group
damien.wyart at free.fr
Wed Apr 8 15:32:43 CEST 2015
* Mattias Ugelvik <uglemat at gmail.com> in comp.lang.python:
> I'm making a string manipulation tool in which I need to know this
> Take this example: re.match('(?P<first>a?)(?P<second>b?)', '')
> I need to know that 'first' is group #1, and 'second' is group #2.
> I need this to resolve certain ambiguities.
Building a mapping between the results of groups and groupdict on the
match object should be quite straightforward.
More information about the Python-list