I want to write a regex in re.VERBOSE
mode, but I'm not confident that I'll add the verbose part without error.
I remember that, theoretically, the equivalence of two regexes (without backreferences, at least) can be found by generating their automata and trying to find a graph bijection. But there's no instance method I can see for comparing regexes.
Is there a way to either generate the automaton of a regex or directly compare them, preferably with the standard library?
(I've already decided on a different solution to my problem, but this is still of interest to me.)
re.compile
caching its results,re.DEBUG
might not give output. And that it's not theoretical equivalence of regex, so this only works forre.VERBOSE
changes. Here is my implementation, with examples: pastebin.com/DeCWLmF8 (Feel free to add from this comment to your answer.) – Execrative