0

The following command should output the string "st":

:echo matchstr('test', '\(\?<=e\).*')

However, it leads to the error mentioned in the title. Reading :h E866 didn't help much. I also tried changing the escapes in the expression (i.e. \(?<=e\).*, \(\?\<=e\).*, \(?\<=e\).*, etc...), but to no avail.

What's wrong with my usage of ?<=, and how may I fix it?

2

(?<=pattern) is from the perl regex dialect. In vim, this concept is spelled \%(pattern\)\@<=. So a full working example would be:

echo matchstr('test', '\(\%(e\)\@<=\).*')
" prints st

In the case where the pattern that precedes \@<= is a single atom, the inner \%() group can be omitted. For example,

echo matchstr('test', '\(e\@<=\).*')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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