const regex = /[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('[\\da-fA-F]{8}-[\\da-fA-F]{4}-[\\da-fA-F]{4}-[\\da-fA-F]{4}-[\\da-fA-F]{12}', 'gm')
const str = `4af06d20-10d5-4d9f-bfce-ca2724a82803
2a3e42b3-f3d44501-89ee-835164dcecd6f (-f3d44501-)
d7e3c311-b5b4-4c9f-a3df-a56b8512f60b
2193cf3f-8da8-4d8a-9103-c91cca66889c
80112dcf-bec8-428d-8f0-b4fd0ca506d5c (-8f0-)
{a8fbdb9f-56ac-44c9-a74f-21b393e57e57}
51b16c80-901c-4270-93a7-120a8cGb42ab ("G")
e257613b-ca10-412e-aeaf-0597db11162c
4ed178df-7575-457f-aef1-03b44b68e55H ("H")
a5E5108-5e54-4-28-b406-83a2-9a711bc4 (-4-28-)
Power Scheme GUID: 0f916538-c8d5-4144-be2a-ee82eccf6413 `;
// 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