用正则表达式过滤掉文件中的指定邮箱地址,正则表达式邮箱地址,[Python]代码#c


[Python]代码

#coding=utf8# 过滤掉域名为10个字符的邮箱import reimport osimport sysdef mail_filter(srcfile, pattern):    fin = open(srcfile, 'r')    for line in fin:        pat = re.compile(pattern)        m = pat.match(line)        # 没有匹配则输出        if not m:            print line,     fin.close()if __name__ == '__main__':    srcfile = 'in'    destfile = 'out'    # 重定向标准输出到文件    fout = open(destfile, 'w')    sys.stdout = fout    mail_filter(srcfile, r'\w{10}@\w*\.\w*')    fout.close()

评论关闭