Suppose I am given the following kind of string:
"(this is (haha) a string(()and it's sneaky)) ipsom (lorem) bla"
and I want to extract substrings contained within a topmost layer of parentheses. I.e. I want to obtain the strings:"this is (haha) a string(()and it's sneaky)"
and "lorem"
.
Is there a nice pythonic method to do this? Regular expressions are not obviously up to this task, but maybe there is a way to get an xml parser to do the job? For my application I can assume the parentheses are well formed, i.e. not something like (()(().