I have a string;
String value = "(5+5) + ((5+8 + (85*4))+524)";
How can I split/extract logical values from this string inside parenthesis as;
(85*4) as one
(5+8 + one) as two
(two+524) as three
((5+5) + three) as four
...
Any idea? all is welcome
This cannot be done using some cleaver regular expression (regular expressions can not “count parenthesis”). Your best option is to use some parser generator and parse the string into an abstract syntax tree (AST for short).
Have a look at JFlex/JavaCUP for instance.
As it turns out, the CUP manual actually has an example covering your situation: