http://www.perlmonks.org?node_id=531680


in reply to Testing regex equivalence

I'm not sure what exactly your goal is. Every regular expression of a certain size either has no loops or it has loops, and if it has loops, there is a certain string length after which parts of the regular expression repeat (I believe this is more or less the pumping lemma). So to find out whether two regular expressions are equal, you need to check all strings below the maximum of the two respectice string lengths.

But this idea only works for "real" regular expressions (in the computer science meaning), not for Perl Regular Expressions in general. So it will help to know if your regular expressions are regular or not.

If they are regular in the CS sense, you can parse the regular expression and then convert it into a finite state machine. Then you "just" need to create all strings of length smaller or equal to twice the number of states, and check for those strings if they either match both or fail both regular expressions.