const regex = /(?P<event_message>A user account was locked out\.)\s+Subject:\s+Security ID:\s+(?P<subject_security_id>.*?)\s+Account Name:\s+(?P<subject_account_name>.*?)\s+Account Domain:\s+(?P<subject_account_domain>.*?)\s+Logon ID:\s+(?P<subject_logon_id>.*?)\s+Account That Was Locked Out:\s+Security ID:\s+(?P<locked_out_security_id>.*?)\s+Account Name:\s+(?P<locked_out_account_name>.*?)\s+Additional Information:\s+Caller Computer Name:\s+(?P<add_info_caller_computer_name>.*)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?P<event_message>A user account was locked out\\.)\\s+Subject:\\s+Security ID:\\s+(?P<subject_security_id>.*?)\\s+Account Name:\\s+(?P<subject_account_name>.*?)\\s+Account Domain:\\s+(?P<subject_account_domain>.*?)\\s+Logon ID:\\s+(?P<subject_logon_id>.*?)\\s+Account That Was Locked Out:\\s+Security ID:\\s+(?P<locked_out_security_id>.*?)\\s+Account Name:\\s+(?P<locked_out_account_name>.*?)\\s+Additional Information:\\s+Caller Computer Name:\\s+(?P<add_info_caller_computer_name>.*)', 'g')
const str = `A user account was locked out. Subject: Security ID: S-1-5-18 Account Name: WIN2K12-TEST\$ Account Domain: WORKGROUP Logon ID: 0x3E7 Account That Was Locked Out: Security ID: S-1-5-21-2883959765-1550083997-3048789898-1018 Account Name: Test Additional Information: Caller Computer Name: NB00887902`;
// 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