python正则-文本预处理

import re
 
# make English text clean
def clean_en_text(text):
    # keep English, digital and space
    comp = re.compile('[^A-Z^a-z^0-9^ ]')
    return comp.sub('', text)
 
# make Chinese text clean
def clean_zh_text(text):
    # keep English, digital and Chinese
    comp = re.compile('[^A-Z^a-z^0-9^\u4e00-\u9fa5]')
    return comp.sub('', text)
 
if __name__ == '__main__':
    text_en = '$How old are you?$'
    text_zh = '$你好!我是个程序媛,中国新生代农民工。$'
    print(clean_en_text(text_en))
    print(clean_zh_text(text_zh))
上一篇:LibreOffice(开源免费办公软件)


下一篇:centos修改中文显示