I guess my question is best explained with an (simplified) example.
Regex 1:
^\\d+_[a-z]+$
Regex 2:
^\\d*$
<
I finally found exactly the library that I was looking for:
dk.brics.automaton
Usage:
/**
* @return true if the two regexes will never both match a given string
*/
public boolean isRegexOrthogonal( String regex1, String regex2 ) {
Automaton automaton1 = new RegExp(regex1).toAutomaton();
Automaton automaton2 = new RegExp(regex2).toAutomaton();
return automaton1.intersection(automaton2).isEmpty();
}
It should be noted that the implementation doesn't and can't support complex RegEx features like back references. See the blog post "A Faster Java Regex Package" which introduces dk.brics.automaton.