I have a really simple question (punny right).
What is the simplest form of this regular expression?
(((0|1)*(00)(0|1)*)((0|1)*(11)(0|1)*))|(((0|1)*(11)(0|1)*)((0|1)*(00)(0|1)*))
I'm creating a regular expression that accepts a language for all binary strings that contain the substrings 00 and 11 (in any order).
The expression I have now works, but I'm sure it can be simplified.
This is almost the same regex. I only converted the (0|1) into [01], added a [01]* to the left and right shared for both cases (11 first or 00 first) and removed some parenthesis that were not necessary:
[01]*(00[01]*11|11[01]*00)[01]*
Stating with
(((0|1)*(00)(0|1)*)((0|1)*(11)(0|1)*))|(((0|1)*(11)(0|1)*)((0|1)*(00)(0|1)*))
__^^^^^_____^^^^^___^^^^^_____^^^^^______^^^^^_____^^^^^___^^^^^_____^^^^^___
Replace all (0|1) by [01]
(([01]*(00)[01]*)([01]*(11)[01]*))|(([01]*(11)[01]*)([01]*(00)[01]*))
_______^^^^____________^^^^_______________^^^^____________^^^^_______
Remove parenthesis around (00) and (11) as you do not want to capture this group and you do not have a *, +, ? behind the parenthesis. Therefore it is not required because of ambiguity.
(([01]*00[01]*)([01]*11[01]*))|(([01]*11[01]*)([01]*00[01]*))
_^____________^^____________^___^____________^^____________^_
Remove yet more parenthesis that does not solve any ambiquity:
([01]*00[01]*[01]*11[01]*)|([01]*11[01]*[01]*00[01]*)
________^^^^^^^^^^_________________^^^^^^^^^^________
Collapse [01]*[01]* into [01]* which means exactly the same.
([01]*00[01]*11[01]*)|([01]*11[01]*00[01]*)
_^^^^^_________^^^^^___^^^^^_________^^^^^_
Extract common prefix and suffix [01]*
[01]*(00[01]*11|11[01]*00)[01]*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With