The following regex:
(?:X-)?Received: (?:by|from) ([^ \n]+)
will, for the following lines, match the text in bold:
Received: 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
Received: by 10.66.156.198 with SMTP id wg6mr62843415pab.126.1433365924352;
Received: from localhost (localhost [127.0.0.1])
If I alter the text such that "Received by: " and "Received: from " are removed in each line, leaving me with:
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
by 10.66.156.198 with SMTP id wg6mr62843415pab.126.1433365924352;
from localhost (localhost [127.0.0.1])
How do I update the regex then to just match the IP addresses or domains (e.g. mail.oknotify2.com, 10.66.156.198) in this text?
I can reduce it to (?:by|from) ([^ \n]+)
and that will give me "from mail.oknotify2.com", "by 10.66.156.198" etc. But how do I go the last step and omit the "by " and "from ", leaving only the domain/IP address? The final regex should also, as the original, ignore subsequent domains/IPs per line where present e.g. mx.google.com in the first line.