Match a template that is not followed by a sub-entry in Vim

Suppose I have a file with lines that contain the following lines:

...cat dog lorem ipsum...
...cat lizard ...
...cat bird ...
...cat dog ...

I want to write a regular expression that matches strings that catshouldn't dog:

...cat lizard ...
...cat bird ...

How can i do this?

+4
source share
1 answer

Forward to coincide with the atom, following it with the help @!. In this case, the atom that we want to not match is the capture group corresponding to the line dog:

/\vcat (dog)@!

Broken:

  • \vactivates very magic parsing mode
  • (dog)matches the string dogand puts it in capture group 1
  • @! (dog), , dog

cat ( ), dog.

+7

Source: https://habr.com/ru/post/1622363/


All Articles