const regex = /^TEXT\h([A-Z0-9]{14})/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^TEXT\\h([A-Z0-9]{14})', 'gm')
const str = `Material B7E671143D244B
====================================
TEXT 2F3139D816C34D 1
TEXT B6A968EF2505A2 1
TEXT 35206697A04F91 1
TEXT EB485AF490D83D 1
TEXT 0DAB42294BD9B3 1
TEXT 3D6525BEE360E1 0
Material D6906B886B06E3
====================================
TEXT 0CCECCCCFB62AE 1
TEXT 1E14CB29AB43F0 1
TEXT FB7F0DCE9B5950 1
Material 431831490FD5C9
====================================
TEXT 9D77B6474696D8 1
TEXT D04DEE5DF130A4 1
TEXT B6A968EF2505A2 1
TEXT 8C37245A4F0F81 1
TEXT A39FAFFC5ABC06 1
TEXT D24199644F2EE6 1`;
// 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