const regex = /\bid\s+:\s*\b([0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12})\b/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\bid\\s+:\\s*\\b([0-9a-f]{8}\\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\\b[0-9a-f]{12})\\b', 'gm')
const str = `id : 42cdb643-0a11-416b-b66b-7bb28a9a20ea
isReadOnly : False
somestring : False
somestring : {}
name :
id : d006d69e-8d04-48d7-8806-cdc39c18e679
somestring : False
somestring : False
somestring : 822F0340-818A-4F23-AA78-633B6436913F
upstreamDataflowsOfDatasets : {}`;
// 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