How can I split a string like “4(2(3)(1))(6(5))” into parts like

[4, 2(3)(1), 6(5)]? Basically, the structure of the string is formatted to represent a tree like this “root(left_subtree)(right_subtree)”. This is a recursive definition. I came across this task from trying to solve this problem:

https://www.lintcode.com/problem/construct-binary-tree-from-string/description

I’m not sure how to use regular expressions to solve this in JAVA.