I have a mail log file, which is like this:
Aug 15 00:01:06 **** sm-mta*** to=,
Try regex
module.
x="""Aug 15 00:01:06 **** sm-mta*** to=,,user3@aol.com, some_more_stuff
Aug 16 13:16:09 **** sendmail*** to=, some_more_stuff
Aug 17 11:14:48 **** sm-mta*** to=,, some_more_stuff"""
import regex
print regex.findall(r"sm-mta.*to=\K|\G(?!^).+?@(.*?)[>, ]", x, version=regex.V1)
Output:
['', 'gmail.com', 'yahoo.com', 'aol.com', '', 'gmail.com', 'gmail.com']
Just ignore the first empty match.
https://regex101.com/r/7zPc6j/1