I have this situation(Java code):
1) a string such as : “A wild adventure” should match.
2) a string with adjacent repeated words: “A wild wild adventure” shouldn’t match.
With this regular expression: .* \b(\w+)\b\s*\1\b.* i can match strings containing adjacent repeated words.
How to reverse the situation i.e how to match strings which do not contain adjacent repeat words
Use negative lookahead assertion,
(?!pattern).Explanation courtesy of Rick Measham’s
explain.pl:See also
Related questions
Note
Negative assertions only make sense when there are also other patterns that you want to positively match (see examples above). Otherwise, you can just use boolean complement operator
!to negatematcheswith whatever pattern you were using before.