Keep It Simple, Stupid | |
PerlMonks |
Re: mutual exclusion of regexesby blokhead (Monsignor) |
on Apr 14, 2009 at 00:02 UTC ( [id://757306]=note: print w/replies, xml ) | Need Help?? |
Yes, it is certainly possible to decide this property. Put another way, given two regular expressions, you want to know whether their intersection is empty.
From a theoretical point of view, it is no problem to compute the intersection of two regular expressions. From a practical point of view, it is a bit of a pain, since you must convert to DFAs somewhere along the way. NFAs and regular expressions aren't immediately amenable to the intersection operation. Keep in mind that these kinds of problems (intersecting and/or complementing languages represented as regular expressions) are usually PSPACE-hard, which is even worse than NP-hard. If you don't want to code up algorithms for regular expression → DFA conversion and DFA intersection, you might want to check out this suite that does these kinds of manipulations of regular expressions. The authors (myself and another monk) have not worked on it for quite some time, but I think that this simple kind of functionality is in the code. I believe that something like this would work: Extending this to a large number of regular expressions means that you must just check the intersection of all pairs of regexes. Update: some related reading: Comparative satisfiability of regexps.; Testing regex equivalence; Negating Regexes: Tips, Tools, And Tricks Of The Trade. blokhead
In Section
Seekers of Perl Wisdom
|
|