简体   繁体   English

如何<a>使用Notepad ++查找/替换功能</a>包装链接<a>?</a>

[英]How to wrap links in <a> with Notepad++ Find/Replace function?

I have a text document with raw links (not wrapped) and I would like to wrap them in HTML anchor tags. 我有一个带有原始链接(未包装)的文本文档,我想将它们包装在HTML锚标记中。

Link example: 链接示例:

http://example.com/images/my-image.jpg

Desired output: 所需的输出:

<a href="http://example.com/images/my-image.jpg">http://example.com/images/my-image.jpg</a>

I can FIND the links in Notepad++ using the following RegEx: 我可以使用以下RegEx在Notepad ++中查找链接:

[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?(\?([-a-zA-Z0-9@:%_\+.~#?&//=]+)|)

However, the REPLACE string I'm trying is not working for some reason: 但是,由于某些原因,我尝试使用的REPLACE字符串不起作用:

<a href="\1">\1</a>

这是记事本++中“查找”对话框的图像

How can I do this with notepad++? 如何使用记事本++执行此操作?

You need to replace with the backreference to the whole match: 您需要使用对整个匹配项的反向引用来替换:

<a href="$&">$&</a>

Or 要么

<a href="$0">$0</a>

Here, the $0 and $& "insert" the text that is matched by the whole regular expression, not just by some capturing groups. 在这里, $0$& “插入”与整个正则表达式匹配的文本,而不仅仅是由某些捕获组匹配。

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

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