slwr
slwr

Reputation: 1175

Python: How to remove text within round brackets?

I tried this but it doesn't work

return re.sub('([^)]*)','', myResultStats.text)

suggestions?

thanks

Upvotes: 3

Views: 7924

Answers (2)

tomdee
tomdee

Reputation: 2439

You need to escape the brackets

return re.sub('\([^)]*\)','', myResultStats.text)

Upvotes: 2

Blender
Blender

Reputation: 298532

Try this:

return re.sub('\(.*?\)','', myResultStats.text)

Parentheses denote capture groups, so you have to escape them.

Upvotes: 9

Related Questions