Re: Get named groups from a regular expression

2014-07-03 Thread Philip Shaw
On 2014-07-01, Florian Lindner wrote: > > Is there a way I can extract the named groups from a regular > expression? e.g. given "(?P\d)" I want to get something > like ["testgrp"]. The match object has an attribute called "groupdict", so you can get the found named groups using match.groupdict.k

Re: Get named groups from a regular expression

2014-07-02 Thread Devin Jeanpierre
On Tue, Jul 1, 2014 at 8:58 AM, Chris Angelico wrote: > On Wed, Jul 2, 2014 at 1:29 AM, Peter Otten <__pete...@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,

Re: Get named groups from a regular expression

2014-07-01 Thread jkn
On Tuesday, 1 July 2014 16:12:34 UTC+1, Florian Lindner wrote: > Hello, > > > > Is there a way I can extract the named groups from a regular expression? > > e.g. given "(?P\d)" I want to get something like ["testgrp"]. > > > > OR > > > > Can I make the match object to return default val

Re: Get named groups from a regular expression

2014-07-01 Thread Peter Otten
Chris Angelico wrote: > On Wed, Jul 2, 2014 at 1:29 AM, Peter Otten <__pete...@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

Re: Get named groups from a regular expression

2014-07-01 Thread MRAB
On 2014-07-01 16:12, Florian Lindner wrote: Hello, Is there a way I can extract the named groups from a regular expression? e.g. given "(?P\d)" I want to get something like ["testgrp"]. OR Can I make the match object to return default values for named groups, even if no match was produced? i

Re: Get named groups from a regular expression

2014-07-01 Thread Chris Angelico
On Wed, Jul 2, 2014 at 1:29 AM, Peter Otten <__pete...@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. ChrisA -- https://

Re: Get named groups from a regular expression

2014-07-01 Thread Peter Otten
Florian Lindner wrote: > Is there a way I can extract the named groups from a regular expression? > e.g. given "(?P\d)" I want to get something like ["testgrp"]. Easy, just write a regular expression to parse regular expressions ;) (Sorry, I can't contribute something constructive, my first idea

Get named groups from a regular expression

2014-07-01 Thread Florian Lindner
Hello, Is there a way I can extract the named groups from a regular expression? e.g. given "(?P\d)" I want to get something like ["testgrp"]. OR Can I make the match object to return default values for named groups, even if no match was produced? Thanks, Florian -- https://mail.python.org/m