How do I highlight lines that don't have a duplicate line?

I am trying to find a regex to indicate lines that do 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 that contain a word hello

but don't have another hello

on the same line.

Expected Result:
Only lines 3 and 5 need to be selected.

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 an entire line) if there is no double pattern on one line?

+3


source to share


1 answer


Try the following:

^\(\(.*hello.*\)\{2,}\)\@!.*hello.*$

      

explanation



  • \ (. * hello. * \): atom matching the sentence containing hello
  • \ (\ (foo \) \ {2,} \): an atom that matches at least twice an atom \ (foo \)
  • \ @ !: unmatch if the last atom was matched
  • ... * hello. *: match a sentence with a greeting
  • ^ $: to match the whole string

"Match an entire string that does not contain at least hello twice, but contains hello."

+1


source







All Articles