Skip to content

How to ensure regexes in a RegexSet are mutually exclusive? #837

Answered by BurntSushi
damooo asked this question in Q&A
Discussion options

You must be logged in to vote

It's possible in theory, because you can take any two automata and intersect them. If the resulting automata has any reachable match states, then there must be some overlap. Conversely, if there are no reachable match states in the intersection, then the set of strings each regex matches must therefore be disjoint.

But this crate doesn't (and will never) expose the necessary utilities to do such a thing because it's not terribly practical to do in the context of a general purpose regex library. Short of that, I don't know of a way to answer such a query in the general case. If you can assume something about the regexes you're using, then there are likely shortcuts. e.g., [a-z]{2} and [a-z…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by damooo
Comment options

You must be logged in to vote
5 replies
@BurntSushi
Comment options

@damooo
Comment options

@BurntSushi
Comment options

@damooo
Comment options

@BurntSushi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants