> It turned out finding a Python library to parse regexes (and not parse using regexes) was surprisingly difficult. You could use the debug flag (re.compile(regex, re.DEBUG)) to see the AST it parses, but 1) it prints to stdout and 2) we'd need to reparse it again to get our own AST, so it seemed too hacky of an approach:<p>One option is to use the internal and undocumented sre_parse module:<p><pre><code> >>> sre_parse.parse("[AB]C[D-F](G|H)")
[('in', [('literal', 65), ('literal', 66)]), ('literal', 67),
('in', [('range', (68, 70))]), ('subpattern', (1, [('in',
[('literal', 71), ('literal', 72)])]))]
</code></pre>
It's been stable for 10-15 years, and the above works in 2.x and 3.x.