Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re^3: Compare two regex patternsby moritz (Cardinal) |
on Mar 06, 2008 at 10:22 UTC ( [id://672423]=note: print w/replies, xml ) | Need Help?? |
not for all regexps (that would solve the halting problem :-) ), To digress a bit on theory: for regular expressions that isn't hard at all. Once you have a DFA for your regex, you can build the minimal DFA (that can be done in O(n²) or O(n³), not sure...). You can do that for both regexes you compare, and if the DFAs are isomorphic, both regexes are equivalent. Note that checking if two DFAs are isomorphic isn't hard either, because you know the start state. But of course Perl's regexps are not regular (in the CS sense), so you can forget everything I said if you're only after a practical solution.
In Section
Seekers of Perl Wisdom
|
|