# Regular expression for the language containing neither aa nor bb

I want to create a regular expression for the language

$L=\{ w \in \{a,b\} |$ w has neither aa nor bb as a subword$\}$.

I've tried various things, but I can't seem to get the correct regular expression.

• find the pattern a, ab, aba, abab, ababa, ababab, .abababa, ... – Hendrik Jan Jan 1 '18 at 13:41
• or $b, ba, bab, baba, \dots$. Kleene closure of something. – fade2black Jan 1 '18 at 13:42
• Would $((ab)^* \cup (ab)^* a) \cup ((ba)^* \cup(ba)^*b)$ work? – user79878 Jan 1 '18 at 13:44
• @Leonhard It seems you gave your own answer! – Hendrik Jan Jan 1 '18 at 14:08

$((ab)^∗∪(ab)^∗a)∪((ba)^∗∪(ba)^∗b)$ will work.

The possibilities are: $a,ab,aba,ababa,...$ or $b,ba,bab,baba,...$ or empty string