c - Regex with no 2 consecutive a's and b's -


i have been trying out regular expressions lately. now, have 3 symbols a, b , c.

i first looked @ case don't want 2 consecutive a's. regex like:

((b|c + a(b|c))*(a + epsilon) 

now i'm wondering if there's way generalize problem like:

a regular expression no 2 consecutive a's , no 2 consecutive b's. tried stuff like:

(a(b|c) + b(a|c) + c)* (a + b + epsilon) 

but accepts inputs such as"abba" or "baab" have 2 consecutive a's (or b's) not want. can suggest me way out?

if can't negative match perhaps can use negative lookahead exclude strings matching aa , bb? following (see regex 101 more information):

(?!.*(aa|bb).*)^.*$ 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -