import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<EventID>4702<\\/EventID>|<TimeCreated SystemTime='[^']+'\\/>|<Computer>[^<]+<\\/Computer>|<Data Name='[^']+'>[^<]+<\\/Data>:";
final String string = "<Event xmlns='http://schemas.microsoft.com/win/2004/08/events/event'><System><Provider Name='Microsoft-Windows-Security-Auditing' Guid='{54849625-5478-4994-a5ba-3e3b0328c30d}'/><EventID>4702</EventID><Version>1</Version><Level>0</Level><Task>12804</Task><Opcode>0</Opcode><Keywords>0x8020000000000000</Keywords><TimeCreated SystemTime='2024-12-05T14:59:44.9923272Z'/><EventRecordID>2470365</EventRecordID><Correlation ActivityID='{625186de-46eb-0000-1689-5162eb46db01}'/><Execution ProcessID='1408' ThreadID='1600'/><Channel>Security</Channel><Computer>Host</Computer><Security/></System><EventData><Data Name='SubjectUserSid'>S-1-5-20</Data><Data Name='SubjectUserName'> Host $</Data><Data Name='SubjectDomainName'> Host </Data><Data Name='SubjectLogonId'>0x3e4</Data><Data Name='TaskName'>\\Microsoft\\Windows\\SoftwareProtectionPlatform\\SvcRestartTask</Data><Data Name='TaskContentNew'><?xml version=\"1.0\" encoding=\"UTF-16\"?>\n"
+ "<Task version=\"1.6\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\n"
+ "<RegistrationInfo>\n"
+ "<Source>$(@%systemroot%\\system32\\sppc.dll,-200)</Source>\n"
+ "<Author>$(@%systemroot%\\system32\\sppc.dll,-200)</Author>\n"
+ "<Version>1.0</Version>\n"
+ "<Description>$(@%systemroot%\\system32\\sppc.dll,-201)</Description>\n"
+ "<URI>\\Microsoft\\Windows\\SoftwareProtectionPlatform\\SvcRestartTask</URI>\n"
+ "<SecurityDescriptor>D:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)(A;;FR;;;S-1-5-87-2912274048-3994893941-1669128114-1310430903-1263774323)</SecurityDescriptor>\n"
+ "</RegistrationInfo>\n"
+ "<Triggers>\n"
+ "<CalendarTrigger>\n"
+ "<StartBoundary>2024-12-10T07:54:44Z</StartBoundary>\n"
+ "<Enabled>true</Enabled>\n"
+ "<ScheduleByDay>\n"
+ "<DaysInterval>1</DaysInterval>\n"
+ "</ScheduleByDay>\n"
+ "</CalendarTrigger>\n"
+ "</Triggers>\n"
+ "<Principals>\n"
+ "<Principal id=\"NetworkService\">\n"
+ "<UserId>S-1-5-20</UserId>\n"
+ "<RunLevel>LeastPrivilege</RunLevel>\n"
+ "</Principal>\n"
+ "</Principals>\n"
+ "<Settings>\n"
+ "<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\n"
+ "<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>\n"
+ "<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>\n"
+ "<AllowHardTerminate>false</AllowHardTerminate>\n"
+ "<StartWhenAvailable>true</StartWhenAvailable>\n"
+ "<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>\n"
+ "<IdleSettings>\n"
+ "<StopOnIdleEnd>true</StopOnIdleEnd>\n"
+ "<RestartOnIdle>false</RestartOnIdle>\n"
+ "</IdleSettings>\n"
+ "<AllowStartOnDemand>true</AllowStartOnDemand>\n"
+ "<Enabled>true</Enabled>\n"
+ "<Hidden>true</Hidden>\n"
+ "<RunOnlyIfIdle>false</RunOnlyIfIdle>\n"
+ "<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>\n"
+ "<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>\n"
+ "<WakeToRun>false</WakeToRun>\n"
+ "<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>\n"
+ "<Priority>7</Priority>\n"
+ "<RestartOnFailure>\n"
+ "<Interval>PT1M</Interval>\n"
+ "<Count>3</Count>\n"
+ "</RestartOnFailure>\n"
+ "</Settings>\n"
+ "<Actions Context=\"NetworkService\">\n"
+ "<ComHandler>\n"
+ "<ClassId>{B1AEBB5D-EAD9-4476-B375-9C3ED9F32AFC}</ClassId>\n"
+ "<Data><![CDATA[timer]]></Data>\n"
+ "</ComHandler>\n"
+ "</Actions>\n"
+ "</Task></Data><Data Name='ClientProcessStartKey'>26177172834095606</Data><Data Name='ClientProcessId'>2408</Data><Data Name='ParentProcessId'>1368</Data><Data Name='RpcCallClientLocality'>0</Data><Data Name='FQDN'>Host</Data></EventData></Event>";
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