Exclude words with consecutive repeated characters

Say I have a list of these words: mouse, abba, roar, accent

I need a regular expression that will match the mouse and roar, but not an abba or accent, because the last two have consecutive repeated characters (bb and cc).

I managed to create the following pattern to match only WITH words with double consecutive characters:

.*(.)\1.*

However, I need the opposite, but I find it difficult to turn it over.

+4
source share
2 answers

You can use this:

\b(?:([a-z])(?!\1))+\b

lookahead (?!..), , . , , \b .

:

(?![a-z]*([a-z])\1)\b[a-z]+\b
+7

lookahead:

^(?:(.)(?!\1))*$
+4

All Articles