title: Pattern associated to a named group
body: <p>The following code gives all the named groups used in a pattern.</p>
  
  <pre><code>import re
  
  pattern = r"(?P&lt;DEF_FUNC&gt;def (?P&lt;NAME_FUNC&gt;\w+)\s*\((.*?)\):)|(?P&lt;OTHERS&gt;\w+)"
  regex   = re.compile(pattern)
  
  for name in sorted(
      regex.groupindex,
      key = regex.groupindex.get
  ):
      print(name)
  </code></pre>
  
  <p>Here is the corresponding output.</p>
  
  <pre><code>DEF_FUNC
  NAME_FUNC
  OTHERS
  </code></pre>
  
  <p>I would like to also have the corresponding patterns so as to obtain the following output.</p>
  
  <pre><code>DEF_FUNC  --&gt; def (?P&lt;NAME_FUNC&gt;\w+)\s*\((.*?)\)
  NAME_FUNC --&gt; \w+
  OTHERS    --&gt; \w+
  </code></pre>
  
  <p>Is there a tricky way to do that without doing it "at hand" via regex searches in the pattern text ? </p>