use strict;
my $str = '****************************************************************
[2020-12-31 10:07:04,967] [INFO ][c.s.d.s.activityLauncher.access] *********************[ ACCESS-END Info ]*********************
- [Date]: [2020-12-31 10:07:04.967]
- [Remote IP]: [10.30.20.20]
- [Correlation ID]: [03d93d63-9e42-4dac-9e0b-1252d149e297]
- [Trace ID]: [e7ca75e6b6d2dac0]
- [Span ID]: [34de12785de46a27]
- [Method]: [dmIndivCheck]
- [RESPONSE TIME]: [49ms]
- [Args]: [[IndivRequestParamDTO(DCOL_DATA_ID=EDP20201231100704849-MXNI_DCP_1, ACTIVITY_ID=EDP_DCOL_RESPONSE_DECISION, MODEL_UUID=fbb02026-6ace-4901-be2e-93c2d7341af6)]]
';
my $regex = qr/\[Remote IP\]:\s\[(?<remoteIp>([0-9\.]{0,}))\]/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