const regex = /Group:\s+Security\s+ID:\s+[^\\]*\\(.+?)\s+(?:Account|Group)\s+Name:/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('Group:\\s+Security\\s+ID:\\s+[^\\\\]*\\\\(.+?)\\s+(?:Account|Group)\\s+Name:', 'g')
const str = `<13>Jan 09 12:33:50 TESTSRV1 AgentDevice=WindowsLog AgentLogFile=Security PluginVersion=7.2.4.86 Source=Microsoft-Windows-Security-Auditing Computer=corp.devnet.com OriginatingComputer=TESTSRV1 User= Domain= EventID=4755 EventIDCode=4755 EventType=8 EventCategory=13826 RecordNumber=1244048130 TimeGenerated=1483983229 TimeWritten=1483983229 Level=0 Keywords=0 Task=0 Opcode=0 Message=A security-enabled universal group was changed. Subject: Security ID: CORP\\TESTUSR1 Account Name: TESTUSR1 Account Domain: CORP Logon ID: 0x220f7a57 Group: Security ID: CORP\\VirtualUsers Group Name: VirtualUsers Group Domain: CORP Changed Attributes: SAM Account Name: - SID History: - Additional Information: Privileges: -
<13>Jan 09 12:33:50 TESTSRV1 AgentDevice=WindowsLog AgentLogFile=Security PluginVersion=7.2.4.86 Source=Microsoft-Windows-Security-Auditing Computer=corp.devnet.com OriginatingComputer=TESTSRV1 User= Domain= EventID=4755 EventIDCode=4755 EventType=8 EventCategory=13826 RecordNumber=1244048130 TimeGenerated=1483983229 TimeWritten=1483983229 Level=0 Keywords=0 Task=0 Opcode=0 Message=A security-enabled universal group was changed. Subject: Security ID: CORP\\TESTUSR1 Account Name: TESTUSR1 Account Domain: CORP Logon ID: 0x220f7a57 Group: Security ID: CORP\\VM Admins Group Name: VM Admins Group Domain: CORP Changed Attributes: SAM Account Name: - SID History: - Additional Information: Privileges: -
Group: Security ID: CORP\\Some Strange Account Name:`;
// 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