use strict;
my $str = 'LogName=Security
SourceName=Microsoft-Windows-Security-Auditing
EventCode=5145
EventType=4
Type=Success Audit
ComputerName=xxxx
Category=11111
CategoryString=none
RecordNumber=xxxx
Message=A network share object was checked to see whether client can be granted desired access.
Subject:
Security ID:
Account Name:
Account Domain:
Logon ID:
Network Information:
Object Type: File
Source Address:
Source Port:
Share Information:
Share Name:
Share Path: \\
Relative Target Name: x.dxmdg.com\\Policies\\{123456789456456456454654464546464558655}\\Machine\\Preferences\\Registry\\Registry.xml
Access Request Information:
Access Mask:
Accesses:
Access Check Results:';
my $regex = qr/(?ms)EventCode\=5145.*Message\=A network share object was checked to see whether client can be granted desired access./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