开发者

How I match an HTML attribute using Notepad++ regular expression search?

开发者 https://www.devze.com 2023-01-14 00:05 出处:网络
Here is my text: <span class=\"c1\">Testing \"this string\"</span> and I want to end up with this:

Here is my text:

<span class="c1">Testing "this string"</span>

and I want to end up with this:

<span>Testing "this string"</span>

so I tried to use this regex in Notepad++ to replace with nothing:

 class=".*"

but that matches this:

 class="c1">Testing "this string"

开发者_如何转开发How do I stop that match after one instance of "?


By default, regular expressions are greedy (and so .* will match as much as it possibly can, which, in your case is c1">Testing "this string). In general, you have two ways of getting around this:

  1. Use a nongreedy (or lazy) modifier (.*?), which will match as little as possible (in your case, just c1). Notepad++ doesn't support lazy modifiers, though.
  2. Specify exactly what you want to match with class="[^"]*", which will match everything that isn't a quote. In general, this is the more optimized solution, as well.


class=".*?"

Will make the * lazy.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号