const regex = /\n\s+Security ID:[^\n]+\n\s+Account Name:\s+(?<accounts>[^\n]+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\n\\s+Security ID:[^\\n]+\\n\\s+Account Name:\\s+(?<accounts>[^\\n]+)', 'gm')
const str = `6/6/19
9:27:22.000 AM
06/06/2019 09:27:22 AM
LogName=Security
SourceName=Microsoft Windows security auditing.
EventCode=4720
EventType=0
Type=Information
ComputerName=CPMASNAAD03.na.cintas.com
TaskCategory=User Account Management
OpCode=Info
RecordNumber=5472484169
Keywords=Audit Success
Message=A user account was created.
Subject:
Security ID: "xxxxxxxxx"
Account Name: Account Creator
Account Domain: xxxxx
Logon ID: xxxxxxx
New Account:
Security ID: "xxxxxx"
Account Name: Account Created
Account Domain: xxxxxxx
Attributes:
SAM Account Name: xxxxxxxx
Display Name: User
User Principal Name: -
Home Directory: -
Home Drive: -
Script Path: -
Profile Path: -
User Workstations: -
Password Last Set: <never>
Account Expires: <never>
Primary Group ID: 513
Allowed To Delegate To: -
Old UAC Value: 0x0
New UAC Value: 0x11
User Account Control:
Account Disabled
'Normal Account' - Enabled
User Parameters: -
SID History: -
Logon Hours: <value not set>
Additional Information:
Privileges`;
// 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