我有一个我在网上搜索的字符串,如下所示:
“trackingId”:“f <0x85>©9 \ u0004 L <0x9b> <0x91> \ u001A <0x87>&\ u0013i T”},{“pendingInvitation”:false
如何从字符串中删除杂散字节 <0x85> , <0x9b> , <0x91> 和 <0x87> ?
<0x85>
<0x9b>
<0x91>
<0x87>
你可以使用 regex :
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))
输出:
"trackingId":"f<0x85>©9+L<0x9b><0x91><0x87>&i+T"},{"pendingInvitation":false "trackingId":"f©9+L&i+T"},{"pendingInvitation":false
我搜索了patten <0x__> ,其中 __ 是长度为2的任何字符或数字 .
<0x__>
__
1 回答
你可以使用
regex
:输出:
我搜索了patten
<0x__>
,其中__
是长度为2的任何字符或数字 .