filtered_text = "\n" . join ( line for line in text . split ( "\n" ) if not re . fullmatch ( r"([^)+" , line . strip ( ) ) ) print ( filtered_text )