I think there is some misunderstanding. Show us your input string. Does it really have |BS| strings in it?
do you actually want to remove as much characters(incl. spaces) before the |BS| sequence as many |BS|? The best would be to show input string, your code and the result. and ask specific question.
do you actually want to remove as much characters(incl. spaces) before the |BS| sequence as many |BS|? The best would be to show input string, your code and the result. and ask specific question.