I have a string coming from a telnet client. This string contains backspace characters which I need to apply. Each backspace should remove one previously typed character.
I wouldn't try to use a regular expression for this, since it's very impenetrable to read and I have the feeling that it's not even possible with plain regular expression without any perl-like regex magic-extensions. My suggestion would be something like (python like pseudocode):
stack = []
for char in str:
if char == BACKSPACE and not stack.isEmpty():
stack.pop()
else:
stack.push(char)
result = ''.join(stack)
It'S immediately clear what happens and how it works.