const regex = /\]\sA\s+(.*)(microsoft|office|azure|o365|onenote|outlook|windowsupdate)(\(\d+\))(com|net|us)(\(\d+\))\s/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\]\\sA\\s+(.*)(microsoft|office|azure|o365|onenote|outlook|windowsupdate)(\\(\\d+\\))(com|net|us)(\\(\\d+\\))\\s', 'gm')
const str = `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)
UDP question info at 0000023A2A31D8A0
Socket = 816
Remote addr 10.106.92.80, port 54599
Time Query=5683788, Queued=0, Expire=0
Buf length = 0x0fa0 (4000)
Msg length = 0x0030 (48)
Message:
XID 0xe32e
Flags 0x0100
QR 0 (QUESTION)
OPCODE 0 (QUERY)
AA 0
TC 0
RD 1
RA 0
Z 0
CD 0
AD 0
RCODE 0 (NOERROR)
QCOUNT 1
ACOUNT 0
NSCOUNT 0
ARCOUNT 0
QUESTION SECTION:
Offset = 0x000c, RR count = 0
QTYPE A (1)
QCLASS 1
ANSWER SECTION:
empty
AUTHORITY SECTION:
empty
ADDITIONAL SECTION:
empty`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions