如何在<a> with Notepad++ Find/Replace function?

时间:2016-02-05 11:05:15

标签: html regex replace notepad++

I have a text document with raw links (not wrapped) and I would like to wrap them in HTML anchor tags.

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:

[-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:

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

This is the image for find dialog in Notepad++

中打包链接

如何使用notepad ++?

1 个答案:

答案 0 :(得分:2)

您需要替换整个匹配的反向引用:

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

或者

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

此处,$0$&&#34;插入&#34;与整个正则表达式匹配的文本,而不仅仅是某些捕获组。