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
You could use re.subn():
import re s = 'AX(p>q)&E((-p)Ur)' while True: s, n = re.subn(r'\([^)(]*\)', '', s) if n == 0: break print(s)
AX&E