const regex = /(?:CN=)(\w+)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:CN=)(\\w+)', 'g')
const str = `CN=Lst-niketech.cis.splunk.admins,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-niketech.cis.splunk.users,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-NikeTech.CIS.SOC,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=ACL.Shareddata.CIS.Shared.Operations.WHQ.Change,OU=ACL,OU=Groups,DC=ad,DC=nike,DC=com|CN=Shareddata.CIS.Shared.WHQ.Change,OU=SharedData,OU=Groups,DC=ad,DC=nike,DC=com|CN=SharedMail.Information.Security.Incident.Reporting.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com|CN=Lst-digitaltech.splunk.security.users,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-digitaltech.splunk.security.lead,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Application.SolarWinds.Xerox.Nike.Users,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.Citrix.Nike.Employees.Users,OU=Citrix,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Nike.NikeTech.NIS.SecOps,OU=Nike,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.Splunk.CIS.Admin.Users,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=lst-Nike.Cloud.Change.Management,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Application.TimeTrack.Users,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=SharedMail.nismonitor.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.SCCM.Reporting.AM,OU=SCCM,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.Casper.Report.User,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.HR.Portal.ESS.NonRetail,OU=Portal,DC=ad,DC=nike,DC=com|CN=Application.HR.Portal.ESS.US,OU=Portal,DC=ad,DC=nike,DC=com|CN=Application.Hightail.Users,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Lst-FE.All,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-All.Exchange.Mailboxes BEAVERTN-SVR-VB,OU=Lists,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.Citrix.WebEx.Users,OU=Citrix,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Lst-NikeTech.CIS.ITSecurity.All,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-Metaframe.Global.Users,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=SharedData.GIPS_AllStar.WHQ.Read,OU=SharedData,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.citrix.shared.webex.users,OU=Citrix,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Lst-NikeTech.CIS.SecOps,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=SharedMail.Firewall.Changes.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com|CN=SharedMail.Nike.Information.Security.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com|CN=SharedMail.IOS.SSLCert.Requests.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com`;
// 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