括号内带有元字符的 Vim 正则表达式 [英] Vim regex with metacharacters inside bracket

查看:43
本文介绍了括号内带有元字符的 Vim 正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 vim 正则表达式中搜索元字符或其他字符?

How can you search for a metacharacter or another character in a vim regular expression?

示例:(我希望它匹配元字符 '\w' 或字符 '-' 1 次或更多次

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

[-\w]\+

但是那个正则表达式并不像我希望的那样工作.它只匹配 -、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.

我已经浏览了 vim 文档,但没有这样的例子.

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:]]\+

检查 :h [:alnum:](和后续行)以获取支持类的完整列表.

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

这篇关于括号内带有元字符的 Vim 正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆