Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #88685
| Date | 2015-04-08 22:54 +0200 |
|---|---|
| Subject | Get nesting of regex groups |
| From | Mattias Ugelvik <uglemat@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.151.1428526500.12925.python-list@python.org> (permalink) |
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).
After looking a bit around, I found this:
>>> sre_parse.parse('(?P<outer>(?P<inner>a))')
[('subpattern', (1, [('subpattern', (2, [('literal', 97)]))]))]
This is all I need, but this is an internal module. Though there
doesn't seem to have been changes from py2 to py3. How inadvisable is
it to use this? Would you blame me?
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Get nesting of regex groups Mattias Ugelvik <uglemat@gmail.com> - 2015-04-08 22:54 +0200
Re: Get nesting of regex groups Denis McMahon <denismfmcmahon@gmail.com> - 2015-04-08 21:30 +0000
Re: Get nesting of regex groups Cameron Simpson <cs@zip.com.au> - 2015-04-09 08:00 +1000
Re: Get nesting of regex groups Mattias Ugelvik <uglemat@gmail.com> - 2015-04-08 23:58 +0200
Re: Get nesting of regex groups Mattias Ugelvik <uglemat@gmail.com> - 2015-04-09 00:15 +0200
csiph-web