简体   繁体   English

匹配记事本++正则表达式中所有出现的html元素属性

[英]Matching all occurrences of a html element attribute in notepad++ regex

I have a file which has hundreds of links like this:我有一个文件,其中有数百个这样的链接:

<h3>aspnet</h3>
<a href="http://example.com/1" icon="data:image/png;base64,iwl1zecylifzn3fz9fr3l4cdjqhigcmjo9m">Ex 1</a>
<a href="http://example.com/2" icon="data:image/png;base64,ivborw0kggoaaaansuheugaaaqcayaaaaf8">Ex 2</a>
<a href="http://example.com/3" icon="data:image/png;base64,jmiaw+f2pwdohka6t+hnyfanbkwoa1olmug">Ex 3</a>

So I want to remove all the elements所以我想删除所有元素

icon="data:image/png;base64,ivborw0kggoaaaansuheugaaabaaaaaqcayaaaaf8..."

from all the lines.从所有行。 I went through the official Notepad++ regex wiki and have come up with this after several trials:我浏览了官方的 Notepad++ regex wiki ,经过多次试验后得出了这个结论:

icon=\"[^\.]+\"

The problem with this is, it is selecting past the second double quote and stopping at the next occurring double quote.问题在于,它选择了第二个双引号并在下一个出现的双引号处停止。 To illustrate, this will select the following content:为了说明,这将选择以下内容:

icon="data:image/png;base64,...jbvebich4sec9zgth1sfue1cdt...">EX 1</a> <a href="

If I modify the above regex to,如果我将上面的正则表达式修改为,

icon=\"[^\.]+\">

Then it is almost perfect, but it is also selecting the > :然后它几乎完美,但它也选择了>

icon="data:image/png;base64,...jbvebich4sec9zgth1sfue1cdt...">

The regex I am looking for would select like this:我正在寻找的正则表达式会选择这样:

icon="data:image/png;base64,...jbvebich4sec9zgth1sfue1cdt..."

I also tried the following, but it doesn't match anything at all我也尝试了以下,但它根本不匹配任何东西

icon=\"[^\.]+\"$

Just match anything but a quote, followed by a quote:只匹配除引号外的任何内容,后跟引号:

icon="[^"]+"

Just tested with notepad++ 6.2.2 and confirmed that this matches correctly as written.刚刚使用 notepad++ 6.2.2 进行了测试,并确认这与写入的内容正确匹配。

Broken down:分解:

icon="

This is fairly obvious, match the literal text icon=" .这是相当明显的,匹配文字文本icon="

[^"]+

This means to match any character that is not a " . Adding the + after it means "one or more times."这意味着匹配任何不是"字符。在它后面添加+表示“一次或多次”。

Finally we match another literal " .最后我们匹配另一个文字"

I am not a notepad++ user.我不是记事本++用户。 so don't know how notepad++ plays with regex, but can you try to replace所以不知道记事本++如何与正则表达式一起玩,但你能尝试替换吗

icon=\\"[^>]* to (empty string) ? icon=\\"[^>]*(empty string)

Try this solution:试试这个解决方案:
This is I just check was working as you wanted it.这是我只是检查是否如您所愿。
The way achieving your goal:实现目标的方式:

Find what: (icon.*")|.*?找到什么: (icon.*")|.*?
Replace with: $1替换为: $1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM