【问题标题】:How to delete a part of line that has a specific beginning and ending on Notepad++?如何删除 Notepad++ 上具有特定开头和结尾的部分行?
【发布时间】:2015-06-26 12:44:29
【问题描述】:

假设,例如,我有一些 HTML 代码,其中包含很多看起来像这样的元素

<div id="1-element" class="1-element">...</div>
<div id="2-element" class="2-element">...</div>
...
<div id="99-element" class="99-element">...</div>
<div id="100-element" class="100-element">...</div>
...

我只需要从整个文档中删除所有 class="*-element" 部分,但在 Notepad++ 中使用正则表达式保留 divs、ids 和其他内容。我怎么能做到?

【问题讨论】:

    标签: regex notepad++


    【解决方案1】:
    \bclass="\d+-element"
    

    这应该会为你做的

    【讨论】:

    • 它应该找到整行的一部分。稍微澄清了我的问题。
    • 如果里面没有空格,它可以工作,但是如果有类似class="element *-element"的东西我该怎么办?
    • @Freeeeez 使用 \bclass="[^"]*element"
    【解决方案2】:

    您可以使用以下正则表达式替换:

    查找内容class="[^"]+-element"(?=[^&gt;]*&gt;)

    替换为:空字符串

    请注意,[^"]+ 将匹配任何内容,而不仅仅是 -element 之前的数字,(?=[^&gt;]*&gt;) 前瞻将确保我们只删除节点内的 class 属性。

    【讨论】:

    • 它也有效,遗憾的是我不能同时将 2 个答案标记为正确。
    • :) 您应该只将最适合您的答案标记为已接受。我很高兴 vks 的解决方案有效,class="ddd-element" 不太可能出现在打开节点之外的文本中。虽然可能。
    【解决方案3】:

    这对我有用:

    • 在 Notepad++ 中,打开搜索窗口,选择替换选项卡。

    • 查找内容:\sclass="\d+-element"

    • 检查正则表达式。

    • 单击全部替换。

    • 结果:

    ...

    ...

    ...

    ...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      • 2021-10-10
      • 2021-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多