匹配嵌套括号的正则表达式

regular expression to match nested brackets

我在 notepad++ 中工作,需要替换

new int[(cw[0] - index) * 2];

它以 "new int" 开头,后跟方括号,可能包含另一对方括号。

这个的正则表达式是什么?

在记事本++中,以下内容应匹配出现:

new int(\[(?>[^\[\]]|(?1))*\])

这是在捕获组中利用递归来匹配嵌套括号,如 "matching balanced constructs" section

中所述