const regex = /((?:(us\-)?repository(?(1)|nocdn)?|h(?:(1)|(3)|(5)|(p))\-(?(6)webs01\-s|repo(?(3)(sitory)?01|(?(4)sitory02|(?(5)sitory03|)))\-v))|repo(?:nocdn|us)\.wip|(?:nocdn|us)\-repository\.gtm|91-228-167-25\.ptr)\.eset\.com/gmi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('((?:(us\\-)?repository(?(1)|nocdn)?|h(?:(1)|(3)|(5)|(p))\\-(?(6)webs01\\-s|repo(?(3)(sitory)?01|(?(4)sitory02|(?(5)sitory03|)))\\-v))|repo(?:nocdn|us)\\.wip|(?:nocdn|us)\\-repository\\.gtm|91-228-167-25\\.ptr)\\.eset\\.com', 'gmi')
const str = `repository.eset.com
us-repository.eset.com
repositorynocdn.eset.com
hp-webs01-s.eset.com
h1-repo01-v.eset.com
h1-repository01-v.eset.com
h3-repository02-v.eset.com
h5-repository03-v.eset.com
91-228-167-25.ptr.eset.com
nocdn-repository.gtm.eset.com
us-repository.gtm.eset.com
reponocdn.wip.eset.com
reponocdn.wip.eset.com
reponocdn.wip.eset.com
repous.wip.eset.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