vim regular expreesion

How to find <foo> but not <<foo>> in following text:

———<foo>——–

———<<foo>>——

I try /\(<<\)\@!\zsfoo,it does’t work correctly.
thanks

>Solution :

You can use

:g/\(<\)\@<!<foo>\(>\)\@!

Or, since < and > are single char strings, you may even discard the grouping parentheses:

:g/<\@<!<foo>>\@!

Details

  • \(<\)\@<! / <\@<! – a location not immediately preceded with < char
  • <foo> – a <foo> string
  • \(>\)\@! / >\@! – immediately to the right, there must be no > char.

Leave a Reply