所以我必须开始\u
其次是各种形式的4个字符的十六进制串的发生(他们不是Unicode对象,但在数据实际字符串,这就是为什么我想清理数据),并希望用空白替换那些事件。正则表达式表达了一个特定的模式
示例文本文件:Hello \u2022 Created, reviewed, \u00e9executed and maintained
对于如:会有串\u2022
和\u00e9
的出现,我想找到\u
,并用4个字符子2022
和00e9
跟在后面的是一起拔出。我正在寻找适合此模式的正确表达式。
示例代码:
import json
import io
import re
files = glob('Candidate Profile Data/*')
for file_ in files:
with io.open(file_, 'r', encoding='us-ascii') as json_file:
json_data = json_file.read().decode()
json_data = re.sub('[^\x00-\x7F]+',' ',json_data)
json_data = json_data.replace('\\n',' ')
json_data = re.sub(r'\\u[0-9a-f]{,4}',' ',json_data)
print json_data
json_data = json.loads(json_data)
print(json_data)
如果我得到它的权利,你需要从字符串中删除Unicode字符? –
@LeonardoChirivì不,这就是为什么我明确提到它们不是实际的unicode字符,而是以数据本身的字符串形式。 –