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