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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -