Vim matches errors with regular expression (?: ([^ F]) fe | ([lr]) f) $

Trying to create a pluralization function using vim script

I have this regex copied from a php script to make a few 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 

E64: ? follows nothing errors E64: ? follows nothing E64: ? follows nothing

I think I do not fully understand this regex, and how can I use it with a vim script?

0
vim
Sep 05 '13 at 4:41
source share
1 answer

The Vim regex dialog is slightly different from the more common POSIX regexes and Perge-compatible regexes.

?: which is used to group without capturing a send, is expressed in Vim as \%(...\) (or \v%(...) in very magical mode). Therefore you should use:

 if 'calf' =~ '\v%([^f])fe|([lr])f)$' 

(Notice how I switched to single quotes to avoid escaping backslashes.)

+2
Sep 05 '13 at 6:36 on
source share



All Articles