1. 程式人生 > >Python讀寫檔案 中文正則匹配

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