美文网首页
Python提取中文字符

Python提取中文字符

作者: 致Great | 来源:发表于2018-10-18 14:19 被阅读18次

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))

相关文章

网友评论

      本文标题:Python提取中文字符

      本文链接:https://www.haomeiwen.com/subject/wnajzftx.html