#!/usr/bin/env python # -*- coding: utf-8 -*- ''' 正则表达式测试 @Auther :liuyuqi.gov@msn.cn @Time :2018/4/16 13:08 @File :test-re.py ''' fh = open(r"test_emails.txt", "r").read() for line in fh.split("\n"): if "From:" in line: print(line) import re for line in re.findall("From:.*", fh): print(line)