Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^4: Compare two regex patterns

by vbar (Novice)
on Mar 06, 2008 at 17:48 UTC ( #672522=note: print w/replies, xml ) Need Help??

in reply to Re^3: Compare two regex patterns
in thread Compare two regex patterns

Well, as ikegami says above, OP didn't ask for regexp equivalence, but for partial ordering, which I personally found quite hard enough :-) - but perhaps that's because I don't know the theory... How would you compare minimal DFAs to find (for example) that matching "aa*b" implies matching "ab"?

Replies are listed 'Best First'.
Re^5: Compare two regex patterns
by Anonymous Monk on Mar 23, 2008 at 00:54 UTC
    Here's how you would do this. Forget minimization, you don't need it. Take NFAs (or DFAs, it doesn't matter) representing all the regexes you want to compare. Mark the final state(s) of each NFA or DFA with something that identifies that particular regex. Then combine them all into a single NFA using alternation. Finally, convert that NFA into a DFA, but when you do, make sure that each final state of the DFA has markers indicating what regex(ex) it was final for.

    Now survey all your final states. If all final states have markers for all the regexes, the regexes are equal. You can also use this to determine if one is a subset of another (all final states have markers for regex1, but only some have markers for regex2), if they overlap (at least one final state had markers for both regexes), or if they are completely disjoint (no final state had markers for both).

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2022-08-11 06:03 GMT
Find Nodes?
    Voting Booth?

    No recent polls found