Vim:匹配字符串的正则表达式 [英] Vim: regular expression to match up to a string

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

问题描述

Vim 中什么正则表达式会匹配所有在下面的刺中最多no.的字符?

What regular expression in Vim will match all characters up to no. in the below sting?

foo, bar, and baz, no. 13, qux

换句话说,匹配必须是foo, bar, and baz,

我是正则表达式的新手,在 Stack 上做了我的研究溢出,一个建议是 .+?(?= no.).但它似乎有效仅具有正则表达式的正则(perl?)风味,而不是

I'm new with regular expressions, did my research here on Stack Overflow, and one suggestion is .+?(?= no.). But it seems to work only with the regular (perl?) flavour of regular expressions, not in Vim.

请帮忙.

对于我想要实现的目标,也许有一个更简单的解决方案.我的最终目标是将 foo、bar 和 baz 放在大括号中,并且我计划使用包含正则表达式的全局替换命令.

Maybe there's a simpler solution to what I'm trying to achieve. My ultimate goal is to put foo, bar, and baz in curly brackets, and I planned to to a global substitution command involving regular expressions.

推荐答案

我的最终目标是将 'foo, bar, and baz' 放在大括号中

My ultimate goal is to put 'foo, bar, and baz' in curly brackets

你可以试试

:s/\v(.*)(, no\.)/{\1}\2/

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

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