Is there a way to match a word not containing a palindrome (be it as long as it may)?
For instance, for a 6-character-long palindrome, foo/bar would match but xbarrabzz/1xoxxoxa14 would not match.
Is there a way to match a word not containing a palindrome (be it as long as it may)?
For instance, for a 6-character-long palindrome, foo/bar would match but xbarrabzz/1xoxxoxa14 would not match.
Use a negative lookahead, for example for length 5/6 (3-letter with middle letter reused or doubled):
^(?:(.)(?!(.)(.)\3?\2\1))*$
See live demo.
But you would have to add another look ahead for each length (which I leave as an exercise for the reader).
You can use \b(?:(?!(\w)(\w)\2?\1)\w)+\b
.
It's a simple negative lookahead that checks if the word contains a structure like xyx
or xyyx
.