Is there a regex to extract sub strings from a string containing multiple parantheses?
For example my string is
String str = "(A(B(C(D(x)))))";
I want to print all the sub strings that lie within any pair of parantheses :
A(B(C(D(x))))
B(C(D(x)))
C(D(x))
D(x)
x
I tried using regex :
Matcher m = Pattern.compile("\\((.*?)\\)").matcher(str);
while (m.find()) {
System.out.println(m.group(1));
}
But this only extracts the sub string it finds between 1st pair of parentheses.