Vim 正向前瞻正则表达式 [英] Vim positive lookahead regex
本文介绍了Vim 正向前瞻正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我仍然不太习惯 vim 正则表达式语法.我有这个代码:
I am still not so used to the vim regex syntax. I have this code:
rename_column :keywords, :textline_two_id_4, :textline_two_id_4
我想将最后一个 id 与 VIM 正则表达式语法中的正向前瞻相匹配.
I would like to match the last id with a positive lookahead in VIMs regex syntax.
你会怎么做?
\id@=_\d$
这不起作用.
这个 perl 语法有效:
This perl syntax works:
id(?=_\d$)
编辑 - 答案:
/id\(_\d$\)\@=
谁能解释一下语法?
推荐答案
如果查看 vim 帮助,没有太多说明:(:h \@=
)
If you check the vim help, there is not much to explain: (:h \@=
)
\@= Matches the preceding atom with zero width. {not in Vi}
Like "(?=pattern)" in Perl.
Example matches
foo\(bar\)\@= "foo" in "foobar"
foo\(bar\)\@=foo nothing
这应该与最后一个 id 匹配:
This should match the last id:
/id\(_\d$\)\@=
用非常神奇"保存一些反斜杠:
save some back slashes with "very magic":
/\vid(_\d$)@=
其实用vim的\zs\ze
看起来更直接:
actually, it looks more straightforward to use vim's \zs \ze
:
id\ze_\d$
这篇关于Vim 正向前瞻正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文