I would like to clear some data that was written from my keyboard using python and regex. Especially when the reverse space was used to correct the error.
Example 1:
[in]: 'Helloo<BckSp> world' [out]: 'Hello world'
This can be done using
re.sub(r'.<BckSp>', '', 'Helloo<BckSp> world')
Example 2:
However, when I have several backspaces, I don’t know how to remove exactly the same number of characters before:
[in]: 'Helllo<BckSp><BckSp>o world' [out]: 'Hello world'
(Here I want to remove "l" and "o" in front of the two reverse windows).
I could just use re.sub(r'[^>]<BckSp>', '', line) several times until <BckSp> left, but I would like to find a more elegant / quick solution.
Does anyone know how to do this?
source share