import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?ms)EventCode=(4624|4634|4625)\\s+.*\\.adm";
final String string = "03/08/2024 04:19:49 PM\n"
+ "LogName=Security\n"
+ "EventCode=4634\n"
+ "EventType=0\n"
+ "ComputerName=XXX\n"
+ "SourceName=Microsoft Windows security auditing.\n"
+ "Type=Information\n"
+ "RecordNumber=XXX\n"
+ "Keywords=Audit Success\n"
+ "TaskCategory=Logoff\n"
+ "OpCode=Info\n"
+ "Message=An account was logged off.\n\n"
+ "Subject:\n"
+ " Security ID: DOMINIO\\user.adm\n"
+ " Account Name: utente\n"
+ " Account Domain: AMADORI\n"
+ " Logon ID: XXX\n\n"
+ "Logon Type: 3\n\n"
+ "This event is generated when a logon session is destroyed. It may be positively correlated with a logon event using the Logon ID value. Logon IDs are only unique between reboots on the same computer.";
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