需要使用Notepad++ RegEx 查找和删除大括号之间的字符

Need to use Notepad++ RegExp to find and remove characters between curly brackets

希望删除下面示例文本中 {} 之间的“#”字符

示例文本:

\(C##nH##{##2##n##+##1}O\)

预期输出:

\(C##nH##{2n+1}O\)

我尝试了什么?

\{[#].*\}
^.+?(?=##\w##)##\K|##(?!$)

非常感谢您的帮助!

您可以使用以下模式:

(?:\{|(?<!^)\G)[^#\r\n]*\K#+(?=.*\})

..并替换为空字符串。

Demo.

细分:

(?:             # Beginning of a non-capturing group.
    \{          # Matches the character '{' literally.
    |           # Alternation (OR).
    (?<!^)\G    # Asserts position at the end of the previous match.
)               # End of the non-capturing group.
[^#\r\n]*       # Matches zero or more characters other than '#' or line breaks.
\K              # Resets the starting point of the match (only include what comes next).
#+              # Matches one or more '#' characters.
(?=.*\})        # A positive Lookahead to make sure the `}` character exists.

您可以使用

查找内容(\G(?!^)(?=[^}]*})|\{)([^#{}]*)#+
替换为</code></p> <p><strong>详情</strong>:</p> <ul> <li><code>(\G(?!^)(?=[^}]*})|\{) - 第 1 组(在替换模式中用 </code> 表示):上一个匹配项 (<code>\G(?!^)) 的末尾,后面跟着除以下以外的任何 0+ 个字符} 然后是 } 或 (|) { char

  • ([^#{}]*) - 第 2 组 (</code>):除 <code>#{}
  • 之外的任意 0 个或多个字符
  • #+ - 一个或多个 # 个字符
  • Notepad++ 演示和设置:

    我认为一种可能性是:

    (?:\{|\G(?!^))[^#}]*\K#
    

    并且什么都不替换。

    在线查看demo


    • (?: - 打开非捕获组。
      • \{ - 匹配文字大括号。
      • | - Alternation/OR.
      • \G(?!^) - 在上一场比赛结束时声明位置,但不在行首。
      • ) - 关闭非捕获组。
    • [^#}]* - 除了主题标签和右花括号之外的任何内容匹配零次或多次。
    • \K- 重置比赛的起点。
    • # - 一个话题标签。