我在文本文件中有以下内容:
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
我正在尝试使用正则表达式
cv_.*?\s
匹配 cv_1
, cv_001
, cv_15
在文中。我知道正则表达式有效。但是,当我在 Vim 中尝试时,它与任何内容都不匹配。我们需要在 Vim 中做一些特别的事情吗?
最佳答案
非贪婪字符 ?
在 Vim 中不起作用;你应该使用:
cv_.\{-}\s
...代替:
cv_.*?\s
以下是匹配的快速引用:
* (0 or more) greedy matching
\+ (1 or more) greedy matching
\{-} (0 or more) non-greedy matching
\{-n,} (at least n) non-greedy matching
关于regex - 带有元字符的vim正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1598516/