title: Is there a way to get the PATTERN for a regex group in a python compiled regex?
body: <p>I am writing a helper to troubleshoot more complex regex patterns, and I was wondering if there was a way of getting the pattern for a numbered or named group in a compiled regex?</p>
  <p>for example, I would like to do something like</p>
  <pre><code>&gt;&gt;&gt; test = re.compile(r'(foo(?P&lt;named1&gt;*.))(the\send)')
  &gt;&gt;&gt; test._subgroup(0)
  &quot;foo(?P&lt;named1&gt;*.)&quot;
  &gt;&gt;&gt; test._subgroup(1)
  &quot;?P&lt;named1&gt;*.&quot;
  &gt;&gt;&gt; test_subgroup('named1')
  &quot;*.&quot;
  &gt;&gt;&gt; test.subgroup(2)
  &quot;the\send&quot;
  </code></pre>
  <p>I did look at <a href="https://stackoverflow.com/questions/66242249/get-group-subpatterns-from-a-compiled-regex-object">Get group subpatterns from a compiled regex object</a>, which suggests parsing the pattern string (which I can do), but I was hoping that these are internally stored in the compiled regex object and could be retrieved instead of having another parser.</p>
  <p>thoughts?</p>