Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: How to remove text within round brackets?

Tags:

python

regex

text

I tried this but it doesn't work

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

suggestions?

thanks

like image 373
slwr Avatar asked May 18 '26 04:05

slwr


1 Answers

Try this:

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

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

like image 63
Blender Avatar answered May 20 '26 01:05

Blender