[英]Replace with Regex in Notepad++
I'm trying to replace the part the text with the same text and some extra, example:我正在尝试用相同的文本和一些额外的内容替换文本部分,例如:
Initial text初始文本
<href="../doc/d5807346.pdf" class="document">3.2.1. EXAMPLE</a></div><div style="clear:both;"></div>
After后
<href="../doc/d5807346.pdf" class="document" download="3.2.1. EXAMPLE">3.2.1. EXAMPLE</a></div><div style="clear:both;"></div>
I'm using in Notepad++ the following Regex:我在 Notepad++ 中使用以下正则表达式:
End result is not what I'm expecting, note the > between class="document" and download:最终结果不是我所期望的,请注意 class="document" 和下载之间的 >:
<href="../doc/d5807346.pdf" class="document"> download="3.2.1. EXAMPLE">3.2.1. EXAMPLE</a></div><div style="clear:both;"></div>
I'm stuck on trying to figure out how to prevent that.我一直在试图弄清楚如何防止这种情况发生。
Try this:试试这个:
Tested in N++在 N++ 中测试
Before: <href="../doc/d5807346.pdf" class="document">3.2.1. EXAMPLE</a></div><div style="clear:both;"></div>
之前: <href="../doc/d5807346.pdf" class="document">3.2.1. EXAMPLE</a></div><div style="clear:both;"></div>
After: <href="../doc/d5807346.pdf" class="document">download="3.2.1. EXAMPLE">3.2.1. EXAMPLE</a></div><div style="clear:both;"></div>
之后: <href="../doc/d5807346.pdf" class="document">download="3.2.1. EXAMPLE">3.2.1. EXAMPLE</a></div><div style="clear:both;"></div>
It's helpful to Use "online Regex tester" for visual debug regular expression使用“在线正则表达式测试器”进行可视化调试正则表达式很有帮助
(class="document")>([^<]+)
查找内容: (class="document")>([^<]+)
$1 download="$2">$2
替换为: $1 download="$2">$2
Explanation:解释:
(class="document") # group 1
> # literally >
([^<]+) # group 2, 1 or more any character that is not "<"
Replacement:替换:
$1 # content of group 1 + a space
download=" # literally
$2 # content of group 2
"> # literally
$2 # content f group 2
Screenshot (before):屏幕截图(之前):
Screenshot (after):截图(之后):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.