這篇文章主要介紹python去除非中文的方法,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
python去除非中文的方法:
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 ...以上是python去除非中文的方法的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。