Get nesting of regex groups

Cameron Simpson cs at
Thu Apr 9 00:00:33 CEST 2015

On 08Apr2015 21:30, Denis McMahon <denismfmcmahon at> wrote:
>On Wed, 08 Apr 2015 22:54:57 +0200, Mattias Ugelvik wrote:
>> Example: re.compile('(?P<outer>(?P<inner>a))')
>> How can I detect that 'inner' is a nested group of 'outer'? I know that
>> 'inner' comes later, because I can use the `regex.groupindex` (thanks to
>> your help earlier:
>Pardon me for stating the obvious, but as the person defining the re, and
>assuming you haven't generated another sub-pattern somewhere in the same
>re with the same name, how can inner ever not be a nested group of outer?

If he has to ask this question, one might presume that he is not the source of 
the regexp. Ergo, he may not know the regexp structure ahead of time for 
whatever reason. I could invent scenarios for that, but perhaps Mattias can 
describe his situation some more.

Cameron Simpson <cs at>

In article <CF3rw3.n0x at> pirih at (Chris Pirih) writes:
| Wotsa zerk?

It's a portable hemispherical perforated spooge flange.
        - Chuck Rogers, car377 at

More information about the Python-list mailing list