使用Notepad ++查找双括号的正则表达式

3
我正在尝试查找在另一个括号内部具有开放和关闭括号的句子,例如(text(more))。我尝试了类似以下的代码\([^\)].*?\( - \(.*\( - ((?:\([^]]*\))+)来匹配至少前两个((但不正确。我认为最好使用惰性量词匹配类似((.*))的内容,并且应该匹配文本中(())之间的任何内容,即使它被分为多行,比如在html代码中。
示例文本:
知道我可以否定字符组aknow that I can negate group of chars aknow that I can negate group of chars aknow that I can negate group of chars aknow that I can negate (group ((of chars aknow that))) I can negate group of chars aknow that I can negate (group (of chars) (aknow) that) I can negate group of chars aknow that I can negate group of chars aknow that I can negate group of chars aknow that I can negate group of chars aknow that I can negate group of chars a 知道我可以否定(group ((of chars a know that I can negate))) group of chars a aknow that I can negate group of chars aknow that I can negat#e g[roup] of chars aknow that aknow that I can negate group of (chars aknow)) that I can negate group of chars aknow that

如果你想匹配右边的任何一个或多个 ),可以使用 \((?:[^()]++|(?R))*\) 或者 \((?:[^()]++|(?R))*\)+ - Wiktor Stribiżew
@Wiktor Stribiżew 感谢您,但是它也可以找到单个的。 - Mike
1
尝试使用\([^()]*(?:(?R)[^()]*)+\) - Wiktor Stribiżew
你可以尝试这个 \(.*?\(.*?\)\) https://regex101.com/r/8ctSO8/1/ - Code Maniac
我编辑标记了这个例子,并且 \([^()]*(?:(?R)[^()]*)+\) 很好地运作了。谢谢 @Wiktor Stribiżew - Mike
显示剩余3条评论
1个回答

2

您可以使用

\([^()]*(?:(?R)[^()]*)+\)

设置:

enter image description here

详情

  • \( - 一个 ( 字符
  • [^()]* - 除了 () 之外的0个或多个字符
  • (?:(?R)[^()]*)+ - 1个或多个重复的
    • (?R) - 整个模式递归
    • [^()]* - 除了 () 之外的0个或多个字符
  • \) - 一个 ) 字符。

enter image description here


太好了,谢谢。你知道如何编辑正则表达式才能让它在grepWin中工作吗?因为我尝试过,但没有结果。 - Mike
@Mike 我看到GrepWin使用Boost,和Notepad++一样。它应该能够正常工作。 - Wiktor Stribiżew
我已经安装了,我会去看一下。 - Wiktor Stribiżew
我还没有理解为什么会发生这种情况。可能是与 Boost 引擎有关的一些怪癖(当前实现的 Boost 库版本为 1.68)。 - Wiktor Stribiżew
我不想替换,我想要实际文件的链接,这样我就可以点击它们并在除NP++之外的其他编辑器中打开以进行检查。我将使用此正则表达式来查找与查询匹配的文件。 - Mike
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接