如何使用 Notepad++ 正则表达式搜索匹配 HTML 属性? [英] How I match an HTML attribute using Notepad++ regular expression search?

查看:35
本文介绍了如何使用 Notepad++ 正则表达式搜索匹配 HTML 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的文字:

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

我想以这样的方式结束:

and I want to end up with this:

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

所以我尝试在 Notepad++ 中使用这个正则表达式来替换:

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

 class=".*"

但与此匹配:

 class="c1">Testing "this string"

如何在一个实例"后停止该匹配?

How do I stop that match after one instance of "?

推荐答案

默认情况下,正则表达式为 贪婪(因此 .* 将尽可能匹配 ,在您的情况下是 c1">Testing "这个字符串).一般来说,您有两种方法可以解决这个问题:

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. 使用 nongreedy(或惰性)修饰符(.*?),它将尽可能少地匹配(在您的情况下,只是 c1).不过,Notepad++ 不支持惰性修饰符.
  2. 使用 class="[^"]*" 准确指定要匹配的内容,这将匹配所有不是引号的内容.通常,这是更优化的解决方案,如好吧.
  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.

这篇关于如何使用 Notepad++ 正则表达式搜索匹配 HTML 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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