【问题标题】:regular expression to remove all other words except the words between special characters in notepad++正则表达式删除除记事本++中特殊字符之间的单词以外的所有其他单词
【发布时间】:2023-01-09 18:34:48
【问题描述】:

我正在尝试在 Notepad++ 中创建一个正则表达式来删除特殊字符之间除外的单词。我正在使用这个正则表达式 \<.*?\> 来删除单词和文本。

例如:
示范文本

random text <ABCD> random text
random text <QWERT> random text
random text <XYZ> random text

输出

random text random text
random text random text
random text random text

我只想要上面正则表达式的反面

例如:
示范文本

random text <ABCD> random text
random text <QWERT> random text
random text <XYZ> random text

输出

<ABCD>
<QWERT>
<XYZ>

【问题讨论】:

    标签: notepad++ regex-replace


    【解决方案1】:

    寻找:

    (?m).+?(<.*?>|$)
    

    用。。。来代替:

    $1
    

    在哪里:

    • (?m) 是激活 multiline mode 的标志
    • .+? 搜索一个或多个字符(但尽可能少)
    • (&lt;.*?&gt;|$) 匹配所需的模式或行尾

    截图

    前:

    后:

    【讨论】:

      【解决方案2】:

      这是(*SKIP)(*FAIL)动词的工作。

      • 控制键+H
      • 找什么:&lt;.+?&gt;(*SKIP)(*FAIL)|.+?
      • 替换为:LEAVE EMPTY
      • 打钩 环绕
      • 选择 正则表达式
      • 取消勾选. matches newline
      • 全部替换

      解释:

      <.+?>       # matches the string to be kept
      (*SKIP)     # skip this match
      (*FAIL)     # considere it failed
        |           # OR
      .+?         # match any character but newline
      

      屏幕截图(之前):

      截图(之后):

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-10
        • 2017-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多