use strict;
my $str = '
from mail.example.com (example.com. [213.239.250.131]) by mx.google.com with ESMTPS id xc4si15480310lbb.82.2014.10.26.06.16.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Oct 2014 06:16:58 -0700 (PDT)
Received: from ssservices1-1 (192.168.20.142) by mail.supershuttle.com (192.168.20.110) with Microsoft SMTP Server id 14.2.347.0; Tue, 21 Apr 2015
Received: from ssservices1-1 (192.168.20.142) by mail.supershuttle.com (192.168.20.110) with Microsoft SMTP (TLS) Server id 14.2.347.0; Tue, 21 Apr 2015
';
my $regex = qr/([a-z0-9]{1,4}:+){3,5}[a-z0-9]{1,4}|(?<!id )(?<!\.)\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b(?!\.)/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html