正则表达式:从一个点到另一个点选择字符串/行(带有多个\n)

正则表达式:从一个点到另一个点选择字符串/行(带有多个\n)

我想选择以 开头<!-- FLAGS_1 -->和结尾的所有行<!-- FLAGS -->

<!-- FLAGS_1 -->
              <div class="cautareField">
                <div align="right">

                  <a href="https://mywebsite.com/pentru-un-zeu.html"><img src="index_files/flag_lang_ro.jpg" title="ro" alt="ro" width="28" height="19" /></a>&nbsp; <a href="https://mywebsite.com/fr/pour-un-dieu.html"><img src="index_files/flag_lang_fr.jpg" title="fr" alt="fr" width="28" height="19" /></a>&nbsp; <a href="https://mywebsite.com/en/love-tender.html"><img src="index_files/flag_lang_en.jpg" title="en" alt="en" width="28" height="19" /></a>&nbsp; <a href="https://mywebsite.com/es/una-oracion-por-un-dios.html"><img src="index_files/flag_lang_es.jpg" title="es" alt="es" width="28" height="19" /></a>&nbsp; <a href="https://mywebsite.com/pt/uma-para-um-deus.html"><img src="index_files/flag_lang_pt.jpg" title="pt" alt="pt" width="28" height="19" /></a>&nbsp; <a href="https://mywebsite.com/ar/love-tender.html"><img src="index_files/flag_lang_ae.jpg" width="28" height="19" title="ar" alt="ar" /></a>&nbsp; <a href="https://mywebsite.com/zh/love-tender.html"><img src="index_files/flag_lang_zh.jpg" width="28" height="19" title="zh" alt="zh" /></a>&nbsp; <a href="https://mywebsite.com/hi/love-tender.html"><img src="index_files/flag_lang_hi.jpg" width="28" height="19" title="hi" alt="hi" /></a>&nbsp; <a href="https://mywebsite.com/de/love-tender.html"><img src="index_files/flag_lang_de.jpg" width="28" height="19" title="de" alt="de" /></a>&nbsp; <a href="https://mywebsite.com/ru/love-tender.html"><img src="index_files/flag_lang_ru.jpg" width="28" height="19" title="ru" alt="ru" /></a>
</div>
</div>
<!-- FLAGS -->

我尝试了许多正则表达式组合,但没有效果:

搜索:<!-- FLAGS_1 -->(\s\n.*?)<!-- FLAGS -->

答案1

  • Ctrl+F
  • 找什么:<!-- FLAGS_1 -->(?:(?!<!-- FLAGS -->).)+<!-- FLAGS -->
  • 查看 相符
  • 查看 环绕
  • 查看 正则表达式
  • 查看 . matches newline
  • Find next

解释:

<!-- FLAGS_1 -->        # literally
                    # Tempered Greedy Token
    (?:                     # non capture group
        (?!<!-- FLAGS -->)      # negative lookahead, make sure we haven't <!-- FLAGS --> in the matched string
        .                       # any character
    )+                      # end group, must appear 1 or more times
<!-- FLAGS -->          # literally

答案2

简单查找字符串:<!-- FLAGS_1 -->\r\n.*?\r\n<!-- FLAGS -->

在哪里:

  • \r\n: 行结束
  • .*?:任意字符串,无贪婪搜索

确保选中“正则表达式”,并且“。”匹配换行符。

答案3

尝试这个

  • Ctrl+F
  • 找什么:<!-- FLAGS_1 -->[\s\S]*?<!-- FLAGS -->[\s\S]*?

相关内容