The simplest way to achieve that (roughly) is the ad-hoc method in connection with a test suite expanded with every string that has been tested, or at least a set of them cherrypicked by a human.
Just do not stop at the first regex that matches an input, but always try to match against all regexes. If it happens that $matching_regexen > 1, you will have to roll up your sleeves in oder to apply optimisations once again, and to re-run your test suite afterwards so you make sure there are no regressions.
Guess how many strings would match against m{.}. A hypothetical program as you imagine would never finish.