Python提取中文字符

2018-10-18  本文已影响18人  致Great

Python提取中文字符,包含数字

import re
m = re.findall('[\u4e00-\u9fa5]+', content)

print(m)
def translate(str):
    line = str.strip()  # 处理前进行相关的处理,包括转换成Unicode等
    pattern = re.compile('[^\u4e00-\u9fa50-9]')  # 中文的编码范围是:\u4e00到\u9fa5
    zh = " ".join(pattern.split(line)).strip()
    # zh = ",".join(zh.split())
    outStr = zh  # 经过相关处理后得到中文的文本
    return outStr

print(translate(content))
上一篇 下一篇

猜你喜欢

热点阅读