【问题标题】:Regex in Notepad++ to find missing word before a stringNotepad ++中的正则表达式在字符串之前查找缺失的单词
【发布时间】:2012-10-19 14:15:11
【问题描述】:

我有一些 html 文件,如果有这些文字,我想找到它们:

id="s"

前面没有这个标签

<div

如果没有,正则表达式会添加它,所以结果是:

<div id="s"

并保留 div 之前或 id="s" 之后的所有内容。

鉴于:

  • id="s" 前面可以有空格或制表符
  • 后面有一些字
  • 缺少的“

【问题讨论】:

    标签: regex notepad++ replace


    【解决方案1】:

    最简单的方法可能是搜索所有出现在任何空格后面的&lt;div id="s"id="s",并将其中任何一个替换为&lt;div id="s"。 (也就是说,与其查找id="s",然后再向后查找&lt;div,只需在搜索中包含&lt;div。)

    查找内容:&lt;div\s*id="s"|\s*id="s"
    替换为:&lt;div id="s"

    之前:

    test
    test <div
    id="s"
    test
    id="s"
    test <div id="s"
    test    id="s"
    <div    id="s"
    test   id="s"
    <div  id="s"
    

    全部替换后:

    test
    test <div id="s"
    test<div id="s"
    test <div id="s"
    test<div id="s"
    <div id="s"
    test<div id="s"
    <div id="s"
    

    您可以在搜索和替换字段中添加前导空格,或者再一次通过在test&lt;div id="s" 之间放回所需的空间。

    【讨论】:

      猜你喜欢
      • 2012-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      • 2011-10-14
      • 1970-01-01
      • 2019-02-20
      • 2011-10-06
      相关资源
      最近更新 更多