fork download
  1. import re
  2. p = re.compile(ur'^(?:by|from) (\S+)', re.MULTILINE)
  3. test_str = u"from mail2.oknotify2.com (mail2.oknotify2.com. [208.83.243.70]) by mx.google.com with ESMTP id dp5si2596299pdb.170.2015.06.03.14.12.03\n\nby 10.66.156.198 with SMTP id wg6mr62843415pab.126.1433365924352;\n\nfrom localhost (localhost [127.0.0.1])"
  4.  
  5. print [x.group(1) for x in re.finditer(p, test_str)]
  6.  
Success #stdin #stdout 0.01s 7736KB
stdin
Standard input is empty
stdout
[u'mail2.oknotify2.com', u'10.66.156.198', u'localhost']