TL;DR: There's no generic solution, but is there something better than a simple (Python) string equality test for identical regexes?
From reading this answer, I gather that a generic solution is theoretically impossible.
However, I work on AutoKey, a Python application that compares a window's title and/or class to more than one regex to determine which of several actions to take when AutoKey is triggered by a particular trigger. See this for the actual issue.
Currently, when a new action is added, its associated regex is checked against all other actions with the identical trigger.
The test in use now is a simple string compare of the two regexs. If they are identical, the new action is not allowed to be added.
This very weak test has proven suficient most of the time, but if it fails, it results in undefined behavior - (probably) the first action discovered to match is used where the search order is implementation dependent.
Most of the regexes used in practice are either pure constant literal strings like kate.kate
or things like .*app_title.*
and .*ivaldi.*|.*brave.*
. They only get weird when a negative window filter is needed (to match all windows except those whose title or class match the expression).
So, given that a perfect solution is unavailable is there some half way measure that will at least be better than a simple equality test?
Is there something that could estimate the likelyhood that two regexes are not mutually exclusive or would at least detect trivial things like .*string
being equivalent to .*.*string
After writing this, I came up with a big improvement in the form of a purely empirical heuristic.
I still want to know if there's a more elegant solution/approach.
Note: I am not expert in any of this, so any suggested improvement has to be fairly simple to understand and implement for it to be useful.