新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
創(chuàng)新互聯(lián)Python教程:python怎么去掉字符串的非中文
python去除非中文的方法:

創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網綜合服務,包含不限于成都網站制作、成都網站建設、武宣網絡推廣、微信小程序定制開發(fā)、武宣網絡營銷、武宣企業(yè)策劃、武宣品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)公司為所有大學生創(chuàng)業(yè)者提供武宣建站搭建服務,24小時服務熱線:18980820575,官方網址:www.cdcxhl.com
import re
def find_chinese(file):
pattern = re.compile(r'[^\u4e00-\u9fa5]')
chinese = re.sub(pattern, '', file)
print(chinese)
def find_unchinese(file):
pattern = re.compile(r'[\u4e00-\u9fa5]')
unchinese = re.sub(pattern,"",file)
print(unchinese)
if __name__ == "__main__":
line = "2019年1月3日 - python去除空格和換行符的方法 一、去除空格 strip().strip() # ...用replace('\',''),后邊的串替換掉前邊的posted @ 2016-07-18 08:53 ..."
print("原文:")
print(line)
print("保留中文:")
find_chinese(line)
print("保留非中文:")
find_unchinese(line)運行結果:
原文:
2019年1月3日 - python去除空格和換行符的方法 一、去除空格 strip().strip() # ...用replace('',''),后邊的串替換掉前邊的posted @ 2016-07-18 08:53 ...
保留中文:
年月日去除空格和換行符的方法一去除空格用后邊的串替換掉前邊的
保留非中文:
201913 - python 、 strip().strip() # ...replace('',''),posted @ 2016-07-18 08:53 ... 當前文章:創(chuàng)新互聯(lián)Python教程:python怎么去掉字符串的非中文
本文地址:http://fisionsoft.com.cn/article/cddochd.html


咨詢
建站咨詢
