Get named groups from a regular expression

Peter Otten __peter__ at web.de
Tue Jul 1 15:00:53 EDT 2014


Chris Angelico wrote:

> On Wed, Jul 2, 2014 at 1:29 AM, Peter Otten <__peter__ at 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.

Hmm, it was a joke.

For a limited number of nestings you should be able to cook something up; I 
think Python allows up to 100 groups, so there is an upper limit of nesting 
levels. You might need a regex implementation that allows more than 100 
groups to parse your regex-parsing regex though...




More information about the Python-list mailing list