[Math] regex for binary string which doesnt contain 11110

regular expressions

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?

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.