Reputation: 8119
I'm trying to find a regex to indicate lines which does not have a duplicate string.
Input:
hi hello hello hi
hello hi hello hi
text hello halo hi
hello hello hi
hello halo hi
hello hello hi
I want to highlight all lines which do contain the word hello
but do NOT have another hello
on the same line.
Expected Output:
Only line 3 and 5 must be highlighted.
I tried with this regex:
\(hello\)\(.*hello.*\)\@!
but it doesn't do what I want to do.
How can I highlight a pattern on a line (or the entire line) when there is no double pattern on the same line?
Upvotes: 3
Views: 112
Reputation: 243
Try this :
^\(\(.*hello.*\)\{2,}\)\@!.*hello.*$
explanation
"Match a whole line not containing at least twice hello but containing hello"
Upvotes: 1