EDIT: Don't waste time reading this question unless you're interested in a good example of why you should always check the :help
first: a severe case of PEBKAC.
Consider the text:
foo
.
.
barbaz
Enter the following search:
/\(foo\_.\{-}bar\)baz
\( \) # a group, containing
foo # 'foo', followed by
\{-} # as few as possible instances of
\_. # anything, including newlines, followed by
bar # 'bar'
baz # followed by 'baz'
It matches!
Now let's insert a positive lookbehind, so we only match the baz
:
/\(foo\_.\{-}bar\)\@<=baz
\@<= # positive lookbehind
E486: Pattern not found: \(foo\_.\{-}bar\)\@<=baz
What's going on?
N.B. To check I'm using the zero-width @<= correctly, I tried removing the multiline part of the regex:
/\(bar\)\@<=baz
This matches the baz
, as expected.
Note also that I tried manually specifying both of Vim's regular expression engines, which didn't help.
Finally, note that using \zs
in place of \@<=
works here, but not in the context in which I actually want to use the expression.
Here's another, arguably even simpler, but even more confusing example:
foo
foo
barbaz
This matches:
/\(foo\nbar\)baz
This matches:
/\(foo\nbar\)\@<=baz
This doesn't match:
/\(foo\nfoo\nbar\)\@<=baz
Am I doing something wrong, is this a documented limitation of Vim's regular expressions, or is it just a bug?