Python讀寫文件 中文正則匹配


讀寫文件 中文正則匹配 

好麻煩 代碼很短 錯誤調了很多

#!/usr/bin/env python
#encoding: utf-8
import re
f=open('10000.txt','r', encoding='UTF-8')
f1=open('result.txt','w')

for line in f.readlines():
    ss = line.split('|||')
    s = ss[0].strip()
    if((re.search('和 |(\d點|月)',s) or re.match('向|個|談|和|於|橋|上|省|市|縣|聚|鄉|鎮|\d',s))and len(s) > 4 and (not re.search("上海|鎮江",s)) ):
        f1.write(line)
        print(line)    
    # f1.writeline(line+"  !")
f.close()
f1.close()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM