Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #88698

Re: How to find out which named regular expression group corresponds to which positional regex group

From Serhiy Storchaka <storchaka@gmail.com>
Subject Re: How to find out which named regular expression group corresponds to which positional regex group
Date 2015-04-09 10:49 +0300
References <CAFPwPpT=Gxi-4xmhVz0wJh0eAMAhejjQaLZFmx2QZoTeukNSxg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.159.1428565752.12925.python-list@python.org> (permalink)

Show all headers | View raw


On 08.04.15 16:23, Mattias Ugelvik wrote:
> I'm making a string manipulation tool in which I need to know this correlation.
>
> 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. I was hopin

 >>> re.compile('(?P<first>a?)(?P<second>b?)').groupindex
mappingproxy({'first': 1, 'second': 2})

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How to find out which named regular expression group corresponds to which positional regex group Serhiy Storchaka <storchaka@gmail.com> - 2015-04-09 10:49 +0300

csiph-web