Its mostly in the title, what I mean by alternating is that there is a single 1 or 0 between two occurrences of 0’s. So no such occurrences of 010 or 000.
I am trying to understand the theoretical nature of the question so I would prefer the answer in terms of just Concatenation, Union, and Closure (10, 1|0, and 10*).
Please note this is NOT a homework question I am just interested in the question, so please no patronizing comments to that affect.
Edit: changed the wording in the first paragraph from “between the occurrences” to “between two occurrences”.
The first important observation is that we can reduce the problem: if S is allowed and is
1or ends with two ones, S concatenated with any allowed sequence remains allowed. So what makes a valid S?1is explicitly in S, and any sequence of more than one1will always end in11and so is in S.01may only be followed by another1, as a0would give010. This ends in11, and so is a valid S.00may only be followed by11, as0000,0001and0010all have alternating zeros. This ends in11, and so is a valid S.So that tells us any S matches
^(1|011|0011)*$. But we’re not done, as there are a few other sequences that are not valid for S but are themselves allowed sequences and so could be concatenated to an S.00001001000is not allowed, of course, and anything longer is either in S or is itself not allowed.So the entire regex matching allowed sequences is:
That is zero or more S sequences, optionally followed by one of our allowed non-S sequences.