Get nesting of regex groups

Cameron Simpson cs at zip.com.au
Wed Apr 8 18:00:33 EDT 2015


On 08Apr2015 21:30, Denis McMahon <denismfmcmahon at gmail.com> 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:
>> https://mail.python.org/pipermail/python-list/2015-April/701594.html).
>
>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.

Cheers,
Cameron Simpson <cs at zip.com.au>

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

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



More information about the Python-list mailing list