>>> refuRe = re.compile('\W(hello)\W') >>> b = '{hello}' >>> refuRe.sub('WWW', b) 'WWW' >>> i would like output to be: '{WWW}'