const regex = /Representatives:\s+(?<rep_name>.*)\(.*\)\s+((?<rep2_name>.*)?\s+\()?/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('Representatives:\\s+(?<rep_name>.*)\\(.*\\)\\s+((?<rep2_name>.*)?\\s+\\()?', '')
const str = `----------------------------------------------
SESSION SUMMARY
----------------------------------------------
Representatives:
Amoz Abraham (ID: 23)
Jose Sandoval (ID: 25)
Customer Name: [Pinned] SOUTHLAWN02
Customer's Public IP: 174.110.83.140:56969
Customer's Private IP: 10.5.65.90
Session Start Time: 2020-05-15 17:03:22 US/Pacific
Session End Time: 2020-05-15 17:11:37 US/Pacific
Duration: 00:08:15
# Files Transferred: 0
# Files Moved: 0
# Files Deleted: 0
----------------------------------------------
SYSTEM INFORMATION RETRIEVED
----------------------------------------------
## General ##
Version: Windows 10 Pro x64
Computer Name: SOUTHLAWN02
System BIOS:
Processor 1 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 2 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 3 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 4 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 5 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 6 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Default Browser: Google Chrome
Default Browser Version: 81.0.4044.138
Default Browser Location: C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe
Windows® Directory: C:\\Windows
System Directory: C:\\Windows\\system32
Time Zone: Eastern Daylight Time
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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