提取指定目录下所有以.txt为后缀的文件中包含的手机号码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import os
path = 'e:\\tel'
for i in os.listdir(path):
if i.endswith('.txt'):
print i
with open(os.path.join(path, i), 'r') as f:
#print(f.read())
result = re.compile(r'1[3|4|5|7|8|9][0-9]{9}', re.I).findall(f.read())
print('\n'.join(result))
过滤手机号码
原文:http://blog.51cto.com/9473774/2066837