python - How to remove parentheses only around single words in a string -
let's have string this:
s = '((xyz_lk) stuff (xyz_l)) (and more stuff (xyz))'
i remove parentheses around single words obtain:
'(xyz_lk stuff xyz_l) (and more stuff xyz)'
how in python? far managed remove them along text using
re.sub('\(\w+\)', '', s)
which gives
'( stuff ) (and more stuff )'
how can remove parentheses , keep text inside them?
re.sub(r'\((\w+)\)',r'\1',s)
use \1
or backreferencing.
Comments
Post a Comment