【发布时间】:2021-06-26 08:46:54
【问题描述】:
我正在尝试根据括号拆分java中的字符串,可能存在嵌套括号,例如:
"{one two {three}}{one {two} {{three}}}"
我想要的是一个数组
array [0] = {one two {three}}
array [1] = {one {two} {{three}}}
我尝试使用 \ {(. *?) \} 正则表达式,但我得到了类似的子字符串
{one two {Three}
不考虑哪个是正确的右括号
我该怎么做?
【问题讨论】:
-
是否有任意嵌套或者你知道最大深度吗? See demo for max 2 level deep
-
对不起,我写错了,2组括号之间没有空格。不,不幸的是我不知道深度限制。
-
见ideone.com/D5mj9i,不需要正则表达式。