How to determine if a regex is orthogonal to another regex?

后端 未结 13 531
余生分开走
余生分开走 2020-12-13 16:40

I guess my question is best explained with an (simplified) example.

Regex 1:

^\\d+_[a-z]+$

Regex 2:

^\\d*$
<         


        
13条回答
  •  失恋的感觉
    2020-12-13 16:58

    Convert each regular expression into a DFA. From the accept state of one DFA create an epsilon transition to the start state of the second DFA. You will in effect have created an NFA by adding the epsilon transition. Then convert the NFA into a DFA. If the start state is not the accept state, and the accept state is reachable, then the two regular expressions are not "orthogonal." (Since their intersection is non-empty.)

    There are know procedures for converting a regular expression to a DFA, and converting an NFA to a DFA. You could look at a book like "Introduction to the Theory of Computation" by Sipser for the procedures, or just search around the web. No doubt many undergrads and grads had to do this for one "theory" class or another.

提交回复
热议问题