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

标签 regex notepad++ regex-lookarounds

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

\(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.

关于regex - 需要使用 Notepad++ RegEx 来查找和删除大括号之间的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62946749/

相关文章:

php - 用多个替换器替换多个字符

regex - 如何按长度对一系列行进行排序?

regex - 使用正则表达式在 Notepad++ 中格式化文本 block

javascript - 正则表达式向前看和向后看

javascript - 在 Javascript 中通过匹配替换

javascript - Regex Javascript - 无效的正则表达式 : Nothing to repeat for number input

特殊字符的Java replaceAll正则表达式[

regex - 在 Notepad++ 正则表达式中匹配(并删除)LF 字符

html - Notepad++ RegEx 删除 2 个 html 标签之间的所有内容(中间有换行符)

php - 用逗号分割,后面不跟小写字母