I have to learn regular expressions at last
>>> import re >>> s = 'it BS|BS||BS||BS||BS||BS|this is o n |BS||BS||BS||BS||BS|an example' >>> new_s = s.replace('|BS|', '\b') >>> new_s 'it BS\x08\x08\x08\x08\x08this is o n \x08\x08\x08\x08\x08an example' >>> while '\x08' in new_s: ... new_s = re.sub('[^\x08]\x08', '', new_s) ... >>> new_s 'this is an example' >>>Thanks to this