我正在尝试查找在另一个括号内部具有开放和关闭括号的句子,例如(text(more))。我尝试了类似以下的代码
示例文本:
知道我可以否定字符组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
\([^\)].*?\(
- \(.*\(
- ((?:\([^]]*\))+)
来匹配至少前两个((
但不正确。我认为最好使用惰性量词匹配类似((.*))的内容,并且应该匹配文本中(())
之间的任何内容,即使它被分为多行,比如在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\([^()]*(?:(?R)[^()]*)+\)
。 - Wiktor Stribiżew\(.*?\(.*?\)\)
https://regex101.com/r/8ctSO8/1/ - Code Maniac\([^()]*(?:(?R)[^()]*)+\)
很好地运作了。谢谢 @Wiktor Stribiżew - Mike