Wednesday, April 15, 2009

vim regex negative match

I know how to negate a single character match using the

[^x] - for a single character
[^a-z] - for a range of characters

I needed to be able to do a negative match (that is, match everything EXCEPT the regex pattern) for a project.

The easiest way I found that worked for my little problem was using the


command. This is similar to the :g// command except that it returns everything except the regex matches.

I think that you might also be able to use the negative lookahead regex pattern. I will save that for a future article.

Update: The negative look-ahead assertion articles is here!


Jeremy Stein said...

Ah, :v was helpful. Thanks!

raoul said...

You're welcome! :)

Anonymous said...

Excelent tip!!
That was really great!