const regex = /(?i)[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?i)[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}', 'gm')
const str = `e876c866-1dd6-4c32-bf27-7ab673b57f75
d9da6fe0-cf69-40ae-9263-a115aac94441
bc783e58-3cac-4efb-92ee-560b696674c8
7b054304-c5dd-4595-a390-fd4f4b700e33
20255eea-5679-4fa7-8e65-4bab69425727
8039e4c6-4032-4065-8723-b0351d4a33f0
e9b3f927-b87a-459a-8a5b-caba3ccc8968
edbdb831-6e92-4241-8ba9-0bba71a1d7b0
087b5b52-97e6-4341-8976-59674ecbef2d
d78be4c5-a0ba-4ef4-ab77-97585aa61436`;
// 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