【问题标题】:Regex keep only lines with ".de"正则表达式只保留带有“.de”的行
【发布时间】:2016-11-14 01:19:51
【问题描述】:

我有一个包含域的文档,例如

http://www.example.me/?p=1 
http:/example.de/index.php 
http://www.example.com/index.php/hello-world/ 

现在有不同的结尾(.me .com .de ....)我只想保留带有 .de 结尾的行

谢谢

【问题讨论】:

  • 你什么都没试过?看来您只是来这里复制粘贴答案,而不是研究几秒钟。

标签: regex replace notepad++ line


【解决方案1】:

您可以使用此模式^(?!.*\.de).*$ 并使用正则表达式仅修改 URL 中不包含 .de 的行

请注意,您需要 NotePad++ 6 或更高版本。 请看下面的演示:

【讨论】:

    【解决方案2】:

    preg_match 帮助您执行正则表达式匹配。你可以像这样keep lines with .de

    <?php
    if (preg_match("#\.de#", "www.example.de")){
    //Keep line
    }
    >
    

    【讨论】:

      【解决方案3】:

      试试这个正则表达式进行域搜索:

      ^https?:\/\/(www\.)?example\.de\/

      【讨论】:

      • 我怀疑这些域不会都包含单词"example"
      猜你喜欢
      • 1970-01-01
      • 2015-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多