Regular Expressions 101

Community Patterns

Odd [abc] non-consecutive repeat

1

Regular Expression
Python

r"
((((?<!a)a)|((?<!b)b)|((?<!c)c))((((?<!a)a)|((?<!b)b)|((?<!c)c))(((?<!a)a)|((?<!b)b)|((?<!c)c)))*)?
"

Description

Recognizes strings containing {a,b,c} an odd number of times that do not repeat the same letter twice in a row. Also recognizes null string.

Submitted by anonymous - 8 years ago