import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\]\\sA\\s+(.*)(microsoft|office|azure|o365|onenote|outlook|windowsupdate)(\\(\\d+\\))(com|net|us)(\\(\\d+\\))\\s";
final String string = "10/6/2023 6:19:18 AM 149C PACKET 0000023A2A31D8A0 UDP Rcv 10.106.92.80 e32e Q [0001 D NOERROR] A (6)mobile(4)pipe(4)aria(9)microsoft(3)com(0)\n"
+ "UDP question info at 0000023A2A31D8A0\n"
+ " Socket = 816\n"
+ " Remote addr 10.106.92.80, port 54599\n"
+ " Time Query=5683788, Queued=0, Expire=0\n"
+ " Buf length = 0x0fa0 (4000)\n"
+ " Msg length = 0x0030 (48)\n"
+ " Message:\n"
+ " XID 0xe32e\n"
+ " Flags 0x0100\n"
+ " QR 0 (QUESTION)\n"
+ " OPCODE 0 (QUERY)\n"
+ " AA 0\n"
+ " TC 0\n"
+ " RD 1\n"
+ " RA 0\n"
+ " Z 0\n"
+ " CD 0\n"
+ " AD 0\n"
+ " RCODE 0 (NOERROR)\n"
+ " QCOUNT 1\n"
+ " ACOUNT 0\n"
+ " NSCOUNT 0\n"
+ " ARCOUNT 0\n"
+ " QUESTION SECTION:\n"
+ " Offset = 0x000c, RR count = 0\n"
+ " QTYPE A (1)\n"
+ " QCLASS 1\n"
+ " ANSWER SECTION:\n"
+ " empty\n"
+ " AUTHORITY SECTION:\n"
+ " empty\n"
+ " ADDITIONAL SECTION:\n"
+ " empty";
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