#!coding=utf-8 import re import sys def compile_mail(file_path): #匹配想要的邮箱,去除不想要的内容 address = re.compile( ‘‘‘ (?![\w\d.+][email protected]) #去除不想要的邮箱 [\w\d.+]+ #匹配前缀 @ ([\w\d.]+\.)+ #匹配域名 com #匹配结尾 ‘‘‘, re.UNICODE | re.VERBOSE) with open(r‘c:\333.txt‘) as fd: for x in fd: match = address.search(x) if match: print match.group() if __name__ == ‘__main__‘: file_path = sys.argv[1] compile_mail(file_path)
时间: 2024-10-12 15:51:05