开发者

Vim regex with metacharacters inside bracket

How can you search for a meta开发者_如何转开发character or another character in a vim regular expression?

Example: (I would like this to match the metacharacter '\w' or the character '-' 1 or more times

[-\w]\+

But that regex does not work like I would hope it would. It only matches -, w and . I have tried to escape the '\' but that doesn't work.

I have looked through the vim documentation, but there is no example of this.


Inside a collection, you have to use special character classes. The following expression is equivalent to yours:

[-_[:alnum:]]\+

Check :h [:alnum:] (and subsequent lines) for a complete list on supported classes.


\%(\w\|-\)*

Using \%( group so nothing is captured. \| for alternation between \w and -

or with very magic, with \v

\v%(\w|-)*


There is a plugin called eregex.vim which translates from PCRE to Vim's syntax, expanding [\w] to [0-9A-Za-z_], among many other thing that it does. It takes over a thousand lines of vim to achieve that translation!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜