Removing contents within brackets in string [duplicate]

Try this:

import re

s = "I want to remove all words in brackets( like (this) and ((this)) and ((even) this))."

while True:
    s_new = re.sub(r'\([^\(]*?\)', r'', s)
    if s_new == s:
        break
    s = s_new

print(s_new) # I want to remove all words in brackets.

Leave a Comment