import re s='{[a] abc (b(c)d)}' rx = re.compile(r'\([^()]*\)|\[[^][]*]|[{}]') while rx.search(s): s = rx.sub('', s) print(s.strip())