Say I have a list of words like this: mouse, abba, roar, accent
I need a regex that will match mouse and roar, but not abba or accent, because the last two have consecutive repeat characters (bb and cc).
I managed to come up with the following pattern to match only the words WITH double consecutive characters:
.*(.)\1.*
However what I need is the opposite, but I am having a hard time inverting it.
You can use this:
\b(?:([a-z])(?!\1))+\b
it use a negative lookahead (?!..)
which tests that each capture is not followed by itself. To be sure that the pattern doesn't cut a word before the word end or begin in the middle of a word, I added word boundaries \b
on each side.
An other way:
(?![a-z]*([a-z])\1)\b[a-z]+\b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With