Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'example:': 0.03; 'url:pipermail': 0.05; 'detect': 0.07; 'nested': 0.07; 'skip:` 10': 0.07; 'changes': 0.15; '(1,': 0.16; '(2,': 0.16; 'url:html)': 0.16; 'bit': 0.19; '>>>': 0.22; 'this?': 0.23; 'this:': 0.26; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'me?': 0.32; 'url:python': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'module.': 0.36; 'url:org': 0.36; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; 'subject:Get': 0.68; 'around,': 0.84; 'subject:groups': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=tXRDGMb8ZVSVACVdRkNa/Un+GnSCoxizJWJzBmrMmF8=; b=jarrGqT3GSVTqCD5DUU3aRp0KbORTJQ9w14XDjXsQTB/lLBb4yppMq5VOKV0otZIkR JRBnbjOu+nIuYlSJO0zLDlARg8V1YvT+FqTSN5AN+8CuG//enHHK7Pa5804WNsozOFn7 GHpemefVb0w4e2qMPW705biuzBxcml8xYkew5a/erzk4TETb0/JqJ8yh3FOopn1dWo7z oVKsywpyBZkNlC8O3lEjIzbdKHwothqkXrXbLx2ELiw6ZXUMuEOZXW9ZOqUueWHA8805 WlaCRII4yTPyB8OLbcYLh5K9RU0VtOEgzvHQ0r3HZxYN05KLorIY57LOGc/UpOGHdOBd Q8hQ== MIME-Version: 1.0 X-Received: by 10.107.137.218 with SMTP id t87mr42775309ioi.3.1428526497504; Wed, 08 Apr 2015 13:54:57 -0700 (PDT) Date: Wed, 8 Apr 2015 22:54:57 +0200 Subject: Get nesting of regex groups From: Mattias Ugelvik To: python-list@python.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1428526500 news.xs4all.nl 2876 [2001:888:2000:d::a6]:42441 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88685 Example: re.compile('(?P(?Pa))') 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(?Pa))') [('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?