regex for binary string which doesnt contain 11110

1.2k Views Asked by At

Here's my attempt, although I'm not sure if i missed any edge cases:

$(0,10,110,1110)^*(1)^*$

it seems to work for any random string i test in a regex program, but is this correct?

1

There are 1 best solutions below

1
On BEST ANSWER

Yes, it’s correct. Every $0$ in such a string must be preceded by at most three ones, so the regular expression $(0,10,110,1110)^*$ generates every possible acceptable string ending in a zero. The last zero, if any, can be followed by any number of ones, so $(0,10,110,1110)^*(1)^*$ picks up everything.