Notepad ++多次修改具有相同字符串和附加文本的字符串

bea*_*boy 2 notepad++ regex

在下面的线程上提出了一个类似的问题,我能够让它部分工作 Notepad++ 在常量字符串中查找和替换 不想创建一个新问题,因为想通过在评论中询问来寻求一些帮助,但我的声誉是少所以必须创建一个新问题。

我有一个格式的文本文件,其中重复了以下示例多次

this is random text
https://helloworld.com

another random text
https://iamdoinggood.com

more random text
https://howareyou.com
Run Code Online (Sandbox Code Playgroud)

问题是仅将以 https:// 开头的字符串替换为类似

this is random text
<span"><a href="https://helloworld.com">https://helloworld.com</a></span><br />

another random text
<span"><a href="https://iamdoinggood.com">https://iamdoinggood.com</a></span><br />

more random text
<span"><a href="https://howareyou.com">https://howareyou.com</a></span><br />
Run Code Online (Sandbox Code Playgroud)

我尝试使用 find 和替换正则表达式勾选来执行此操作,使用命令

——([https].*)

替换——<span"><a href="\1">\1</a></span><br />

但它不仅修改以 https:// 开头的字符串,还修改其他文本并给出如下结果,即混淆正常文本的某些部分,并向其添加额外的 html 标签,这是不打算的

this is random text
<span"><a href="https://helloworld.com">https://helloworld.com</a></span><br />

ano<span"><a href="ther random text">ther random text</a></span><br />
<span"><a href="https://iamdoinggood.com">https://iamdoinggood.com</a></span><br />

more random <span"><a href="text">text</a></span><br />
<span"><a href="https://howareyou.com">https://howareyou.com</a></span><br />
Run Code Online (Sandbox Code Playgroud)

关于我在这里可能遗漏的任何帮助

Was*_*sif 5

您的 RegEx 有问题。

  • 按 Ctrl+H 打开查找和替换。
  • 将“查找内容:”设置为(https://.*).
  • 将“替换为:”设置为<span"><a href="\1">\1</a></span><br />
  • 然后在搜索模式组中检查正则表达式。
  • 然后单击全部替换。

您的问题是,[https]如果有h,t,p,s字符而不是整个字符串,它将匹配。

在此处输入图片说明