Vim Tips Wiki
m (fixing category)
(Redirect to VimTipp802)
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
#REDIRECT [[Search_for_lines_not_containing_pattern_and_other_helpful_searches]]
[[Category:Searching]]
 
  +
{{duplicate|802|1180}}
{{Tip
 
  +
{{TipImported
 
|id=220
 
|id=220
  +
|previous=219
|title=Regexp: Match every word except 'foo'
 
  +
|next=222
|created=February 25, 2002 22:28
+
|created=2002
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Michael Geddes
 
|author=Michael Geddes
 
|version=6.0
 
|version=6.0
 
|rating=52/26
 
|rating=52/26
 
|category1=Searching
|text=
 
  +
|category2=
This is a regular expression that matches all words except 'foo'
 
 
}}
 
This is a regular expression that matches all words except 'foo'
  +
<pre>
  +
\v<(foo>)@!\k+>
  +
</pre>
   
 
*<code>\v</code> Very magic
<pre>\v&lt;(foo&gt;)@!\k+&gt;</pre>
 
 
*<code><</code> Start-of-word
 
 
*<code>(Foo>)</code> The atom 'Foo' followed by end-of-word
*\v Very magic
 
 
*<code>@!</code> Match (with zero length) when the previous atom doesn't match.
*&lt; Start-of-word
 
 
*<code>\k+</code> Match one or more Keywords
*(Foo&gt;) The atom 'Foo' followed by end-of-word
 
 
*<code>></code> Match end-of-word.
*@! Match (with zero length) when the previous atom doesn't match.
 
*\k+ Match one or more Keywords
 
*&gt; Match end-of-word.
 
   
 
The non-magic version is:
 
The non-magic version is:
   
  +
<pre>
<pre>\&lt;\(foo\&gt;\)\@!\k\+\&gt;</pre>
+
\<\(foo\>\)\@!\k\+\>
}}
 
  +
</pre>
  +
 
The use of <code>\@!</code> can be very tricky. According to the Vim help files, it is often easier to use <code>\@<!</code> instead. For example, to find all 'bar' strings unless they are part of 'foobar', use the following (non-magic):
  +
<pre>
 
\(foo\)\@<!bar
  +
</pre>
   
  +
==References==
Note, the use of \@! can be very tricky. According to the vim help files, it is often easier to use \@<! instead. For example, to find all "bar" strings unless they are part of "foobar", use the following (non-magic):
 
  +
*{{help|/\@!}}
<pre>\(foo\)\@<!bar</pre>
 
   
  +
==Comments==
<!-- parsed by vimtips.py in 0.462915 seconds-->
 

Latest revision as of 15:37, 1 July 2013

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 220 Printable Monobook Previous Next

created 2002 · complexity intermediate · author Michael Geddes · version 6.0


This is a regular expression that matches all words except 'foo'

\v<(foo>)@!\k+>
  • \v Very magic
  • < Start-of-word
  • (Foo>) The atom 'Foo' followed by end-of-word
  • @! Match (with zero length) when the previous atom doesn't match.
  • \k+ Match one or more Keywords
  • > Match end-of-word.

The non-magic version is:

\<\(foo\>\)\@!\k\+\>

The use of \@! can be very tricky. According to the Vim help files, it is often easier to use \@<! instead. For example, to find all 'bar' strings unless they are part of 'foobar', use the following (non-magic):

\(foo\)\@<!bar

References[]

Comments[]