6333
![vim match errors out with regular expression (?:([^f])fe|([lr])f)$](https://www.xszz.org/skin/wt/rpic/t3.jpg)
Question:
Trying to build pluralize function with vim script
I have this regular expression copied from php script to make plural words
/(?:([^f])fe|([lr])f)$/i \1\2ves
However this does not work with vim
if "calf" =~ "\\v(?:([^f])fe|([lr])f)$"
echo "matched"
end if
it errors out E64: ? follows nothing
I think I don't fully understand this regular expression, and how can I make it use with vim script?
Answer1:Vim's regular expression dialect is slightly different from the more common POSIX regexps and Perl-compatible regexps.
The ?:
which is used for grouping without capturing the submatch is expressed in Vim as \%(...\)
(or \v%(...)
in <em>very magic</em> mode). Therefore, you have to use:
if 'calf' =~ '\v%([^f])fe|([lr])f)$'
(Note how I've switched to single quotes to avoid escaping the backslash.)