Example- 1)(abc)xxx --> output-xxx
2)(abc)(xxx) --> output-xxx
3)((abc)xxx) ---> output-xxx
4)((abc) xxx + yyy)--> output-xxx+yyy
5)((abc)) ---> output-null
Example- 1)(abc)xxx --> output-xxx
2)(abc)(xxx) --> output-xxx
3)((abc)xxx) ---> output-xxx
4)((abc) xxx + yyy)--> output-xxx+yyy
5)((abc)) ---> output-null
trim the String.
find the first closed brackets covering area and if the closing bracket is not at the end trim out that string
recursively call this.
Second step :
search for first piece of string that is enclosed
for: (abc)xxx --> output-xxx
it would be (abc) and check if ')' is last char of String.
here it isn't so we can simply remove(abc) from whole string
in case it is last char consider here
((abc)xxx)
first we will have (abc) first enclosed string , now removed so (xxx) -> xxx this is how.
This actually does what you ask for for all your examples, but I suspect is not what you wanted
[^\)]+\)[\(]*([^\)]*)