I am trying to write a regex query for a language with letters a,b,c such that a is never adjacent to b.
Can it be done by using only the alternation (plus), concatenation and repetition (multiplication) operators?
L = w belongs to {a,b,c}* such that a is never adjacent to b
(Lets see if I recall enough formal language theory.)
Such a regular expression could be built with help of a DFA like this:
Where
A,BandCare states representing the state whena,bandcrespectively was the previous character. Since any character can followcwe can makeCour start state.Fbeing the final end state (end of string).This DFA can be converted to a regular expression like this:
So the expression would be:
Or in informal regex format:
Which can be shortened to: