Q:

How to read text between multi-level parenthetical expressions

I am trying to parse through text to see if it is a valid expression. I am faced with the following problem. 
((5*4) + 3) is a valid expression.
How would I parse this to allow me to analyze what is in one level of parentheses at a time.
For example, I would want to have the following expressions returned in seperate substrings so that one substring reads "5*4" and another seperate substring reads "(5*4) + 3"
I know I can use substring as follows:
String test = "test (542)";

test = test.substring(test.indexOf("(") + 1);
test = test.substring(0, test.indexOf(")"));

But how can I best approach handling multiple levels of parentheses of an unknown string. 

A:

Divide and Conquer would be a promising approach. You could define a recursive function, which will only need to handle a simple base case (like 5*4) explicitly. Whenever there are parentheses, call the function again with the text inside the parentheses.

