Intersection of two regular expressions

后端 未结 4 1638
忘了有多久
忘了有多久 2020-12-17 18:05

Im looking for function (PHP will be the best), which returns true whether exists string matches both regexpA and regexpB.

Example 1:

$regexpA = \'[0         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 18:35

    Theory.

    Java library.

    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();
    }
    

提交回复
热议问题