import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(.*?<LOC0:DBUG>.*|.*?<USER:DBUG>.*|.*?<SYSD:ERRR>.*?(localhost authd: Logout \\(timeout\\)|localhost authd.*?Terminal Services compatibility mode.*?).*|.*?<(SAU.|SYSD):INFO>.*|.*?<(SAU2|USER):NOTE>.*)";
final String string = "04 24 2019 10:38:08 10.62.181.191 <LOC0:DBUG> Apr 24 10:38:08 7A5B3SRVSWMGR01 safeguarding[6351]: RadarLite alerts - Start\n"
+ "04 23 2019 13:54:15 10.62.63.21 <USER:DBUG> Apr 23 13:54:15 localhost trafficlogger: cant stat classnames!\n"
+ "04 23 2019 14:05:26 10.62.63.21 <SYSD:ERRR> Apr 23 14:05:26 localhost authd: Logout (timeout); address 10.62.74.83, username CYMRU\\CTT_McKessonSrvAcc, method NTLM authentication (Terminal Services compatibility mode)\n"
+ "04 23 2019 14:05:25 10.62.63.21 <SAU1:INFO> Apr 23 14:05:25 localhost sshd[29491]: Disconnected from 10.62.181.191 port 42412\n"
+ "04 23 2019 14:05:18 10.62.63.21 <SAU1:INFO> Apr 23 14:05:18 localhost sshd[29388]: Received disconnect from 10.62.181.191 port 42358:11: disconnected by user\n"
+ "04 23 2019 14:05:18 10.62.63.21 <SAU1:INFO> Apr 23 14:05:18 localhost sshd[29391]: Accepted publickey for replication from 10.62.181.191 port 42362 ssh2: DSA SHA256:g1/CZCWVxa2uFJpHF1M6vBaNKPk/NjazYr3vTonagbc\n"
+ "04 23 2019 14:05:12 10.62.63.21 <LOC0:DBUG> Apr 23 14:05:12 localhost safeguarding[7272]: Alert user Email/SMS\n"
+ "04 26 2019 10:19:24 10.62.63.21 <USER:NOTE> Apr 26 10:19:24 localhost smoothwall: Completing replication block 01556270336\n"
+ "04 26 2019 10:18:23 10.62.63.21 <USER:NOTE> Apr 26 10:18:23 localhost smoothwall: Duplicating Changes 01556270276\n"
+ "04 26 2019 10:20:57 10.62.181.191 <USER:NOTE> Apr 26 10:20:57 7A5B3SRVSWMGR01 smoothwall: Replication to child 10.62.181.192 changes 01556270457\n"
+ "04 26 2019 10:29:23 10.62.63.21 <USER:NOTE> Apr 26 10:29:23 localhost smoothwall: Starting replication block 01556270936\n"
+ "04 26 2019 11:23:17 10.62.181.191 <SAU2:NOTE> Apr 26 11:23:17 7A5B3SRVSWMGR01 sudo: datastore : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/datastore_update_hardlinks\n\n"
+ "09 05 2019 16:09:15 10.62.181.192 <SYSD:ERRR> Sep 5 16:09:15 localhost authd: Login; address 10.62.182.165, username CYMRU\\ia039398, method NTLM authentication (Terminal Services compatibility mode)\n"
+ "09 05 2019 16:08:20 10.62.181.192 <SYSD:ERRR> Sep 5 16:08:20 localhost authd: Login; address 10.62.182.135, username CYMRU\\Re111052, method NTLM authentication (Terminal Services compatibility mode)\n"
+ "09 05 2019 16:06:34 10.62.181.192 <SYSD:ERRR> Sep 5 16:06:34 localhost authd: Login; address 10.62.180.125, username CYMRU\\Ne036088, method NTLM authentication (Terminal Services compatibility mode)\n"
+ "09 05 2019 09:04:41 10.69.137.81 <SYSD:INFO> 2019:09:05-09:04:40 wf-tg-utm-2 httpproxy[26178]: id=\"0001\" severity=\"info\" sys=\"SecureWeb\" sub=\"http\" name=\"http access\" action=\"pass\" method=\"GET\" srcip=\"10.69.200.24\" dstip=\"\" user=\"\" group=\"\" ad_domain=\"\" statuscode=\"200\" cached=\"1\" profile=\"REF_HttProContaInterNetwo4 (Clients (DHCP/Static))\" filteraction=\"REF_HttCffWbsBlock (WBS Block)\" size=\"8365\" request=\"0xdaedee00\" url=\"http://download.windowsupdate.com/c/msdownload/update/others/2019/05/28899896_af8426aef8898787eb12d87b445645febda3def8.cab\" referer=\"\" error=\"\" authtime=\"0\" dnstime=\"0\" aptptime=\"65\" cattime=\"0\" avscantime=\"0\" fullreqtime=\"563\" device=\"0\" auth=\"2\" ua=\"Windows-Update-Agent/10.0.10011.16384 Client-Protocol/2.0\" exceptions=\"av,auth,content,url,ssl,certcheck,certdate,mime,fileextension,size,patience\"";
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