use strict;
my $str = '104.126.37.30 - mboylce@bim.om 20/Jul/2022:20:10:01 +0200 "GET /libs/granite/csrf/token.json HTTP/1.1" 200 103 "https://cmx-author.win.com/siteadmin" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"';
my $regex = qr/^(?<aem_access_remote_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s(?<aem_access_domain>\S+)\s(?<aem_access_user>\S+)\s(?<aem_access_date>\S[^:]+):(?<aem_access_bytes_out>\S+)\s(?<aem_access_GMT_offset>[^ ]+)\s"(?<aem_access_request_method>[^ ]+)\s(?<aem_access_request_path>[^ ]+)\s(?<aem_access_request_protocol>[^ ]+)"\s(?<aem_access_status_code>[^ ]+)\s(?<aem_access_request_duration>[^ ]+)\s"(?<aem_access_referrer>[^ ]+)"\s"(?<aem_access_user_agent>.*)"/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