我怎样才能让我的比赛在 vim 中不贪婪? [英] How can I make my match non greedy in vim?

查看:58
本文介绍了我怎样才能让我的比赛在 vim 中不贪婪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含大量标记的大 HTML 文件,如下所示:

I have a big HTML file that has lots of markup that looks like this:

<p class="MsoNormal" style="margin: 0in 0in 0pt;">
  <span style="font-size: small; font-family: Times New Roman;">stuff here</span>
</p>

我正在尝试进行 Vim 搜索和替换以摆脱所有 class=""style="" 但我遇到了麻烦使匹配变得不贪婪.

I'm trying to do a Vim search-and-replace to get rid of all class="" and style="" but I'm having trouble making the match ungreedy.

我的第一次尝试是这样

%s/style=".*?"//g

但 Vim 似乎不喜欢 ?.不幸的是,删除 ? 会使匹配过于贪婪.

but Vim doesn't seem to like the ?. Unfortunately removing the ? makes the match too greedy.

如何让我的比赛不贪婪?

How can I make my match ungreedy?

推荐答案

代替 .* 使用 .\{-}.

%s/style=".\{-}"//g

另见:help non-greedy

这篇关于我怎样才能让我的比赛在 vim 中不贪婪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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