const regex = /^[a-z\d]{8}(?:-[a-z\d]{4}){3}-[a-z\d]{12}\.local$/gim;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^[a-z\\d]{8}(?:-[a-z\\d]{4}){3}-[a-z\\d]{12}\\.local$', 'gim')
const str = `a2aadd61-85d9-4be6-a36c-267ad65917d3.local
ccd58700-cdd5-4c1f-8098-5bc306f1ce77.local
bb4115cd-1f39-42b0-9433-e59533c9c771.local
3b382824-24bf-457a-a7d6-b6e25e4d79bf.local
9284cbaa-2933-45e3-9ae2-c0cccae54b68.local
619281fb-6426-44fa-8d0f-9e58ce415e3e.local
541d8a99-b1a5-46f4-96f1-e31f30b3cb99.local
2feb782f-ea40-4a37-b843-5b5b4fe1860e.local
`;
// 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