簡體   English   中英

如何刪除 Python 中的十六進制字符

[英]How to remove hex characters in Python

我正在嘗試以下

>>> import string
>>> s = 'https://google.com\n<0x03><0x03><0x03>'
>>> s.decode('utf8').encode('ascii', errors='ignore')

預期的 output 為:

'https://google.com'

但是十六進制字符和新行不會被刪除。

這段代碼:

import string
import re
s = 'https://google.com\n<0x03><0x03><0x03>'
s=re.sub(r'[^ -~].*'.format(string.punctuation), '',s)
print(s)

給出了這個:

'https://google.com'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM