Mar-27-2017, 03:41 AM
I'm late to the party, and mine looks a lot like a few of the others, but here's my entry:
orig = 'it |BS||BS||BS|this is one|BS||BS||BS|an example' import re regex = re.compile(r".?\|BS\|") text = orig replacements = 1 while replacements: text, replacements = regex.subn("", text, 1) print(text) # this is an example