Vim positive lookahead regex

不羁的心 提交于 2019-12-28 05:17:27

问题


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

I would like to match the last id with a positive lookahead in VIMs regex syntax.

How would you do this?

\id@=_\d$

This does not work.

This perl syntax works:

id(?=_\d$)

Edit - the answer:

/id\(_\d$\)\@=

Can someone explain the syntax?


回答1:


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

This should match the last id:

/id\(_\d$\)\@=

save some back slashes with "very magic":

/\vid(_\d$)@=

actually, it looks more straightforward to use vim's \zs \ze:

id\ze_\d$


来源:https://stackoverflow.com/questions/18391665/vim-positive-lookahead-regex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!