Vim 中的多行正则表达式支持 [英] Multi-line regex support in Vim

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

问题描述

我注意到用于跨多行匹配的标准正则表达式语法是使用/s,如下所示:

I notice the standard regex syntax for matching across multiple lines is to use /s, like so:

This is\nsome text
/This.*text/s

例如,这在 Perl 中有效,但在 Vim 中似乎不受支持.相反,我必须更加具体:

This works in Perl for instance but doesn't seem to be supported in Vim. Instead, I have to be much more specific:

/This[^\r\n]*[\r\n]*text/

我找不到任何理由说明为什么会这样,所以我想我可能只是错过了 vim 帮助中的相关部分.

I can't find any reason for why this should be, so I'm thinking I probably just missed the relevant bits in the vim help.

有人能以一种或另一种方式确认这种行为吗?

Can anyone confirm this behaviour one way or the other?

推荐答案

是的,Perl 的 //s 修饰符在 Vim 正则表达式上不可用.有关详细信息以及 Vim 和 Perl 正则表达式之间其他差异的列表,请参阅 :h perl-patterns.

Yes, Perl's //s modifier isn't available on Vim regexes. See :h perl-patterns for details and a list of other differences between Vim and Perl regexes.

相反,您可以使用 \_.,这意味着匹配任何单个字符,包括换行符".它比你拥有的要短一点.见:h/\_..

Instead you can use \_., which means "match any single character including newline". It's a bit shorter than what you have. See :h /\_..

/This\_.*text/

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

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