Reputation:
What is the regular expression that generates the language where every odd position in the string is an a? (Please answer with the shortest possible regex: minimal parentheses, no spaces and any piped strings in alphabetical order!)
I assume I'm working with only a's and b's.
(a(a|b))+ would only cover even strings: a(a|b), a(a|b)a(a|b), etc.
How do I also cover the case that the string is odd? ex: a(a|b)a
Note: not using programming syntax
Edit: some valid strings would be: a, aa, aaa, aaaa, aaaaa, ab, aba, abab, ababa, etc.
EDIT: Solution
My instructor gave the answer (aa|ab)*. This is incorrect because it misses case(s), for example "a".
Upvotes: 0
Views: 2200
Reputation: 1
I think this might help you
(1(0+1))*
1((0+1)1)*
Finally the answer is Case 1 + Case 2
Upvotes: 0
Reputation: 1904
^(a.)*a?$
^...$
)See regex101 example here
Upvotes: 0