Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: mutual exclusion of regexes

by blokhead (Monsignor)
on Apr 14, 2009 at 00:02 UTC ( #757306=note: print w/ replies, xml ) Need Help??


in reply to mutual exclusion of regexes

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:

use FLAT; my $r1 = FLAT::Regex->new( $expr1 ); my $r2 = FLAT::Regex->new( $expr2 ); print $r1->intersect($r2)->is_empty ? "disjoint" : "overlapping";
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


Comment on Re: mutual exclusion of regexes
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://757306]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2014-09-23 01:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls