Pretty much what the question says. I came up with
(ba)?(a + bb + bbbbb + aba)*(ab)?
Is there anything more readable? Or is this incorrect?
I know you shouldn’t really be doing this sorta thing with Regex when you can just go !~/bbb/ in your code, but it’s a theory exercise.
Thanks.
Edit for Clarification: I’m not using | to represent the OR bit in the Regex and using + it instead. Sorry for the confusion.
Edit 2: {a,b} is for a language with just ‘a’ and ‘b’ characters. Not {mininum, maximum}. Sorry again.
Edit 3: Because this is part of a theory class, we’re just dealing with the basics of Regex. The only things you’re allowed to use are +, ?, () and *. You cannot use {minimum, maximum).
I think I have a working regex. Let
b°—which is a notation I invented just now—be the regex that matches zero or more b’s, except it won’t match three of them. This can be replaced by(ε | b | bb | bbbb+), so don’t worry that I’m using magic or anything. Now I think that matching strings can be seen as repeating subpatterns of zero or more a’s followed byb°, which could be(a*b°)*, but you need there to be at least one “a” in between sequences of b’s. So your final regex isa*b°(a+b°)*.Since
b°can match the empty string, the initiala*is superfluous as thea+can pick up the initial a’s just fine, so the regex can be optimized down tob°(a+b°)*(thanks, wrikken).