· 8 years ago · Oct 06, 2017, 10:54 AM
1result = []
2for lines in data:
3 if 'sm-mta' in lines:
4 result.extend(re.findall(r'@(.*?.com)',lines))
5
6['gmail.com', 'yahoo.com', 'aol.com', 'gmail.com', 'gmail.com']
7
8x="""Aug 15 00:01:06 **** sm-mta*** to=<user1@gmail.com>,<user2@yahoo.com>,user3@aol.com, some_more_stuff
9Aug 16 13:16:09 **** sendmail*** to=<user4@yahoo.com>, some_more_stuff
10Aug 17 11:14:48 **** sm-mta*** to=<user5@gmail.com>,<user6@gmail.com>, some_more_stuff"""
11import regex
12print regex.findall(r"sm-mta.*to=K|G(?!^).+?@(.*?)[>, ]", x, version=regex.V1)