Question

I would like to immitate the following pattern of searching in vim:

grep "\<[0-9]\>" *  |  grep -v "666"

I can highlight all numbers using

/\<[0-9]\>"

but then how can I tell vim to remove from the highlighted text the ones that match the expression

/666

Can this be done in Visual Studio at least ?

Was it helpful?

Solution

You cannot sequentially filter the matches like in the shell, so you need to use advanced regular expression features to combine both into a single one.

Basically, you need to assert a non-match of 666 at the match position. That's achieved with the \@! atom (in other regular expression dialects, that's often written as (?!...)):

/\%(\d*666\d*\)\@!\<\d\+\>

Note: If you want to only exclude 666, but not 6666 etc. you need to specify \<666\> instead in the first part.

I've used \d instead of [0-9]; you can further strip down the \ use with the \v "very magic" modifier:

/\v(\d*666\d*)@!<\d+>

OTHER TIPS

Of course, /666 doesn't match that expression.

Assuming, though, that you had e.g. \d\+ and wanted to exclude 666, you can use the negative lookahead:

\v((666)@!\d)+

This uses

  • \v for very magic (reducing the number of \ escapes)
  • \@! for "negative zero-width look-ahead assertion"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top