[issue38660] Checking if two regexes are equal should test if they are functionally equivalent

Борис Верховский report at bugs.python.org
Fri Nov 1 04:16:40 EDT 2019


Борис Верховский <boris.verk at gmail.com> added the comment:

I saw two Python regexes, one derived from a regex in the standard library. There was a comment saying that they're interchangeable and I wanted to check if they were actually the same without having to read what all the regex symbols mean. Plus a true comparison would be more correct.

Besides that I don't have a real use case. There's a few people asking about doing this if you Google for "check if two regexes are equivalent". Some for Python specifically.

@serhiy I read what \w meant from the first Google result and got it wrong. Sounds like a good argument for why Python should be able to do this for me :)

Regexes are not Turing complete, so not quite. If I understand it correctly, comparing them is somewhere between comparing two graphs and comparing two programs (which is generally impossible). Theoretically it's a decidable problem, but the extra logic that Python's implementation has (for dealing with unicode and whatever) makes it hard, but it should still be theoretically possible, unless Python's regexes are somehow Turing complete.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38660>
_______________________________________


More information about the Python-bugs-list mailing list