Trying to build pluralize function with vim script
I have this regular expression copied from php script to make plural words
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.
?: which is used for grouping without capturing the submatch is expressed in Vim as
\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.)