Reputation: 30374
I have the following in a text file:
This is some text for cv_1 for example
This is some text for cv_001 for example
This is some text for cv_15 for example
I am trying to use regex cv_.*?\s
to match cv_1
, cv_001
, cv_15
in the text. I know that the regex works. However, it doesn't match anything when I try it in Vim.
Do we need to do something special in Vim?
Upvotes: 7
Views: 3576
Reputation: 881555
vim's regex syntax is a little different -- what you're looking for is
cv_.\{-}\s
(the \{-}
being the vim equivalent of perl's *?
, i.e., non-greedy 0-or-more). See here for a good tutorial on vim's regular expressions.
Upvotes: 5
Reputation: 32763
The non-greedy character ?
doesn't work in Vim; you should use:
cv_.\{-}\s
...instead of:
cv_.*?\s
Here's a quick reference for matching:
* (0 or more) greedy matching
\+ (1 or more) greedy matching
\{-} (0 or more) non-greedy matching
\{-n,} (at least n) non-greedy matching
Upvotes: 19