Is there a way to do negative lookahead in vim regex?

后端 未结 5 1729
一生所求
一生所求 2021-01-31 15:40

In Vim, is there a way to search for lines that match say abc but do not also contain xyz later on the line? So the following lines would match:

<
5条回答
  •  旧巷少年郎
    2021-01-31 15:52

    Your attempt was pretty close; you need to pull the .* that allows an arbitrary distance between the match and the asserted later non-match into the negative look-ahead:

    /abc\(.*xyz\)\@!
    

    I guess this works because the non-match is attempted for all possible matches of .*, and only when all branches have been exhausted is the \@! declared as fulfilled.

提交回复
热议问题