I have a string that I scraped online that looks like this:
"trackingId":"f<0x85>©9\u0004+L<0x9b><0x91>\u001A<0x87>&\u0013i+T"},{"pendingInvitation":false
How do I remove the stray bytes <0x85>
, <0x9b>
, <0x91>
, and <0x87>
from my string?
I have a string that I scraped online that looks like this:
"trackingId":"f<0x85>©9\u0004+L<0x9b><0x91>\u001A<0x87>&\u0013i+T"},{"pendingInvitation":false
How do I remove the stray bytes <0x85>
, <0x9b>
, <0x91>
, and <0x87>
from my string?
You can use regex
:
import re
s = '"trackingId":"f<0x85>©9\u0004+L<0x9b><0x91>\u001A<0x87>&\u0013i+T"},{"pendingInvitation":false'
print(s)
print(re.sub(r'<0x\w{2}>', '',s))
with output:
"trackingId":"f<0x85>©9+L<0x9b><0x91><0x87>&i+T"},{"pendingInvitation":false
"trackingId":"f©9+L&i+T"},{"pendingInvitation":false
I have searched for the patten <0x__>
, where the __
is any char or digit of length 2.