I have a string s with nested brackets: s = \"AX(p>q)&E((-p)Ur)\"
s
s = \"AX(p>q)&E((-p)Ur)\"
I want to remove all characters between all pairs of brackets and
Another simple option is removing the innermost parentheses at every stage, until there are no more parentheses:
p = re.compile("\([^()]*\)") count = 1 while count: s, count = p.subn("", s)
Working example: http://ideone.com/WicDK