Vime regex: match with negation in the middle of a picture

I am trying to learn regex in vim and am stuck with the following problem:

I want to make a replacement that matches all of the following lines - and the like - except the one that contains Look aXXhead

. With this, I only mean anything between a

and head

beyond XX

.

Look ahead
Look aYhead
Look aXhead 
Look aXXhead    
Look aXXXhead   

      

In case it matters, I had the highest hopes when trying

:%s/Look a\(XX\)\@!head/*\0
:%s/Look a\(.*\&\(XX\)\@!\)head/*\0

      

which only matches Look ahead

because of the zero pressure width \(XX\)\@!

I.

Tries like

:%s/Look a\(XX\)\@!.*head/*\0

      

skips the line "triple X".

So how is it done?

PS This is my first post on stack swapping, so please help and correct me in case there are better ways or places for this question.

+3


source to share


2 answers


What about:

/\vLook a(XXhead)@!.*head

      



or without very magic

:

/Look a\(XXhead\)\@!.*head

      

+1


source


Try with this pattern:

/\(Look aXXhead\)\@!\&Look a.*head/

      

It consists of the following parts:



  • \(Look aXXhead\)\@!

    match at every position in the file, but not at /Look aXXhead/

  • Look a.*head

    corresponds also /Look aXXhead/

The operator \&

advises that each of these parts must match in the same position.

+2


source







All Articles