I'm trying to construct a regular expression for the language of binary strings in which every 00 must have at least two 1s before it.
I realize this can be done with lookbehinds using the following regex: ^(?:(?<=11)00(?!0)|(?<=1)0|1+)+$
, however I am now trying to construct a regular expression in the sense of formal language theory.
I currently have (0|)(11*0)*1*
(or (0+ε)(11*0)*1*
), which gives me the language of binary strings without consecutive 0s, but am not quite sure how to get the 'conditional' part in without actually using a conditional.
Accepted:
0
1
10
11100
1100
Rejected:
100
1000
11000
^(?:(?<=11)00(?!0)|(?<=1)0|1+)+$
does not match those strings that start with 0, such as 0, or 01, or 010, etc. It also misses the empty string. – John L. Jan 28 '21 at 02:10