Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 在Sublime文本中,如何查找并用格式化和链接的URL替换所有未编码的web地址?_Regex_Sublimetext2_Find Replace - Fatal编程技术网

Regex 在Sublime文本中,如何查找并用格式化和链接的URL替换所有未编码的web地址?

Regex 在Sublime文本中,如何查找并用格式化和链接的URL替换所有未编码的web地址?,regex,sublimetext2,find-replace,Regex,Sublimetext2,Find Replace,我如何找到并用格式化和链接的URL替换所有未编码的web地址 下面示例中的虚拟文本可以表示不同长度的段落 例如: `之前: Dummy text. website.dk/info Dummy text (website.com) Dummy text. Dummy text. website.dk Dummy text. www.website.com Dummy text. <em><a href="http://website.dk/info

我如何找到并用格式化和链接的URL替换所有未编码的web地址

下面示例中的虚拟文本可以表示不同长度的段落

例如:

`之前:

   Dummy text. website.dk/info
   Dummy text (website.com) Dummy text.
   Dummy text. website.dk
   Dummy text. www.website.com
   Dummy text. <em><a href="http://website.dk/info" target="blank">website.dk/info</a></em>
   Dummy text (<em><a href="http://website.com" target="blank">website.com</a></em>) dummy text.
   Dummy text. <em><a href="http://website.dk" target="blank">website.dk</a></em>
   Dummy text. <em><a href="http://website.com" target="blank">www.website.com</a></em>` 
之后:

   Dummy text. website.dk/info
   Dummy text (website.com) Dummy text.
   Dummy text. website.dk
   Dummy text. www.website.com
   Dummy text. <em><a href="http://website.dk/info" target="blank">website.dk/info</a></em>
   Dummy text (<em><a href="http://website.com" target="blank">website.com</a></em>) dummy text.
   Dummy text. <em><a href="http://website.dk" target="blank">website.dk</a></em>
   Dummy text. <em><a href="http://website.com" target="blank">www.website.com</a></em>` 
虚拟文本。
伪文本()伪文本。
虚拟文本。
虚拟文本
假设“before”只是URL列表:

  • 查找>替换
  • 单击
    *
    以启用正则表达式
  • 在“查找内容”中输入
    (.+)
  • 在“替换为”中输入
  • 单击“全部替换”
  • 如果“before”不是所有的URL,“Find What”将更加棘手


    根据评论,这里有一个(黑客)Python方法

    file.html
    
    
    虚拟文本。网址:www.dk/info
    虚拟文本(website.com)虚拟文本。
    虚拟文本。www.dk.com
    虚拟文本。www.website.com
    

    虚拟文本。 伪文本()伪文本。 虚拟文本。 虚拟文本。

    link_links.py
    导入re;
    def链路_链路(m):
    #链接所有链接。
    返回有关(
    #尝试这种模式;例如,搜索“URL regex”。
    
    r'(?假设您有更多不是链接的文本,那么您可以使用如下正则表达式:

    ((?:www\.)?\w+\.?\w+\/?\w+)
    
    用这个替换字符串

    <em><a href="http://$1" target="blank">$1</a></em>
    
    
    


    谢谢,克里斯。对不起,我不清楚。我修改了问题。“Before”不是一个列表。websites.com是文本段落。此模式基于您的示例:
    (?是HTML。我从杂志文章中发布WordPress帖子。它们有很多电子邮件地址。你必须使用Sublime吗?更好的方法是使用一种语言(Perl、Ruby、Python等)您可以在替换中执行代码。这将允许您隔离所有非HTML内容。可能仍然有一种极好的方法。您可以将我链接到一篇示例文章吗?我对这些语言没有经验,但我不反对使用。