我怎样才能让我的比赛在 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