import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?ms)EventCode\\=5145.*Message\\=A network share object was checked to see whether client can be granted desired access.";
final String string = "LogName=Security\n"
+ "SourceName=Microsoft-Windows-Security-Auditing\n"
+ "EventCode=5145\n"
+ "EventType=4\n"
+ "Type=Success Audit\n"
+ "ComputerName=xxxx\n"
+ "Category=11111\n"
+ "CategoryString=none\n"
+ "RecordNumber=xxxx\n"
+ "Message=A network share object was checked to see whether client can be granted desired access.\n\n"
+ "Subject:\n"
+ "Security ID: \n"
+ "Account Name: \n"
+ "Account Domain: \n"
+ "Logon ID: \n\n"
+ "Network Information:\n"
+ "Object Type: File\n"
+ "Source Address: \n"
+ "Source Port: \n\n"
+ "Share Information:\n"
+ "Share Name: \n"
+ "Share Path: \\\n"
+ "Relative Target Name: x.dxmdg.com\\Policies\\{123456789456456456454654464546464558655}\\Machine\\Preferences\\Registry\\Registry.xml\n\n"
+ "Access Request Information:\n"
+ "Access Mask: \n"
+ "Accesses: \n\n"
+ "Access Check Results:";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html