Question

I want to search words as following in "vi":

"AA" not followed by "BB" or "CC"

i.e.

AAXC... -- OK
AABB... -- NOT OK
AACC... -- NOT OK

Not sure how to do that.

Was it helpful?

Solution

vim supports regex searching and substituting http://vimregex.com/:

That is the desired regex:

AA((?!B{2})|(?!C{2}))

The above regex can be validate here.


In vim:

/^\(AA\)\(BB\)\@!.*$

will find all the AA.. format strings and will skip AABB strings.

  1. in order to skip AACC and AABB you can use:

    /^\(AA\)\(\(BB\)\|\(CC\)\)\@!.*$
    

    or equivalently:

    /^\(AA\)\(\(B\{2\}\)\|\(C\{2\}\)\)\@!.*$
    
  2. eliminate the ^ from the strings if you want to find strings like AAXC inside string of the form BAAXC.

OTHER TIPS

You can search using regular expressions, just use A[^BC], if it's actually that simple (just characters, not words).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top