Say I have a line like this:
s = '((Xyz_lk) some stuff (XYZ_l)) (and even more stuff (XyZ))'
I would like to remove parentheses only around individual words to get:
'(Xyz_lk some stuff XYZ_l) (and even more stuff XyZ)'
How do I do this in Python? So far I have been able to remove them along with the text using
re.sub('\(\w+\)', '', s)
which gives
'( some stuff ) (and even more stuff )'
How can I remove only brackets and save text inside them?
python regex
Cleb
source share