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


Groups > comp.lang.python > #73827

Re: Get named groups from a regular expression

References <louj52$j56$1@ger.gmane.org> <louk4e$1mt$1@ger.gmane.org> <CAPTjJmrudfOR1j2iJ2N2da_mQYdTtNGOhM6aghX5w1vnoe+xQQ@mail.gmail.com>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date 2014-07-02 01:11 -0700
Subject Re: Get named groups from a regular expression
Newsgroups comp.lang.python
Message-ID <mailman.11401.1404288767.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Jul 1, 2014 at 8:58 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Wed, Jul 2, 2014 at 1:29 AM, Peter Otten <__peter__@web.de> wrote:
>> Easy, just write a regular expression to parse regular expressions ;)
>
> Hmm, is that even possible? AIUI you can't make a regex that correctly
> parses nested tokens, and named groups can definitely be nested.

Nesting isn't inherently a problem. Since nesting doesn't change the
way they parse, you can ignore nesting for the purposes of pulling out
named groups. Find each unescaped "(?P<...>".

(Making sure they are unescaped is annoying, though.)

-- Devin

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


Thread

Re: Get named groups from a regular expression Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-07-02 01:11 -0700

csiph-web