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
Post a Comment