Python: how best to combine two regex's into one pattern match? -
given list of email header fields of type receive e.g.:
received: 10.194.174.73 smtp id bq9csp183244wjc; mon, 5 may 2014 17:49:10 -0700 (pdt) x-received: 10.180.14.233 smtp id s9mr18354760wic.53.1399337350112; mon, 05 may 2014 17:49:10 -0700 (pdt) received: mail-wg0-f52.google.com received: mail-ie0-x247.google.com smtp id gx4so163592215ieb.1 <myemailaddress@gmail.com>; mon, 01 jun 2015 18:34:50 -0700 (pdt)
each field reports "hop" either ip address or domain name. i'm looking build regex take care of both.
the following regex's extract ip address , (gmail) domain name respectively:
\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b mail.*com
what's elegant approach combine 2 or more patterns in python? i'll iterating on list of receive fields , running regex against each.
if want capture domains , ips of hops can use regex this.
in python:
import re pat = r'(?:by|for|from) <?([^\s;>]+)' print(re.findall(pat, text))
->
['10.194.174.73', '10.180.14.233', 'mail-wg0-f52.google.com', 'mail-ie0-x247.google.com', 'myemailaddress@gmail.com>']
(edit capture email)
Comments
Post a Comment