1

I have the following text file:

1: This is a book.
2: Here is the book for you.
3: There are book.
4: You can read the book.
5: Is book good to read?

I want to find all occurrences of book not following a or the, that is, the book in Line 3,5 but not those on lines 1,2,4.

I tried to use the following search pattern:

[^a|the] book

however, this is only to check one character, but not the whole word.

1 Answer 1

3

The brackets are for chars. Use subpattern (parentheses) instead.

\%(a\|the\)\@3<! book

\%( ... \) --- a (unnumbered) submatch

a\|the --- "a" or "the"

\@3<! --- NO match behind (3 bytes lookback)

8
  • The 3 shouldnt be necessary, right?
    – D. Ben Knoble
    Commented Oct 14, 2019 at 12:46
  • 2
    @D.BenKnoble Unnecessary, but strongly recommended due to performance issues. See :h /\@<!.
    – Matt
    Commented Oct 14, 2019 at 12:53
  • well, I need to match a word but not led a defined pattern. I think there is a negative lookahead command(?) Commented Oct 15, 2019 at 0:07
  • @Matt It seems @3<1 is not working, After remove 3, (a\|the)\@<! book is a workaround. Commented Oct 15, 2019 at 0:20
  • @ShihSyuanHuang What is "@3<1"? I wrote \@3<!
    – Matt
    Commented Oct 15, 2019 at 3:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.