Search code examples
regexfinite-automata

regular expression for all binary strings that include at least two 0s and at least one 1?


Im thinking it would be (E0*0*EUE1*E)? where E is the set of my alphabet, with at least 2 0s and at least 1 1


Solution

  • Try this expression:

    ^(.*0.*0.*1.*)|(.*0.*1.*0.*)|(.*1.*0.*0.*)$
    

    EDIT Could be simplified to:

    ^.*(0.*0.*1)|(0.*1.*0)|(1.*0.*0).*$