use strict;
my $str = 'Nov 16 14:21:05 192.168.77.20/192.168.77.167 1 2016-11-16T14:21:05+08:00 s_sys@aaa1 snmptrapd 19644 - - \'14:21:5 16/11/2016 UDP: [10.80.0.254]:58919 wcore Cold Start sysUpTimeInstance = 24:16:28:17.07 snmpTrapOID.0 = cmnMacMoveNotification cmnMACMoveAddress.0 = e0:66:78:8a:93:bb cmnMACMoveVlanNumber.0 = 30 cmnMACMoveFromPortId.0 = 1669 cmnMACMoveToPortId.0 = 1668 cmnMACMoveTime.0 = 24:16:28:17.07\'';
my $regex = qr/\[((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\]/p;
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