const regex = /^NEM.[A-Z0-9]{3}.[A-Z0-9]{3,6}.[0-9]{3}.[0-9]{1,3}$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^NEM.[A-Z0-9]{3}.[A-Z0-9]{3,6}.[0-9]{3}.[0-9]{1,3}$', 'gm')
const str = `NEM.ESB.IPAB.400.001
NEM.ESB.IPAB.400.003
NEM.ESB.TST.400.1
NEM.BPM.TST.400.1
NEM.ESB.TSTTST.400.1
NEM.BPM.TSTTST.400.1
NEM.ESB.TST.400.001
NEM.BPM.TST.400.001
NEM.ESB.TSTTST.400.001
NEM.BPM.TSTTST.400.001
NEM.ESB.AAA.000.000
NEM.BPM.AAA.000.000
NEM.ESB.AAAAAA.000.000
NEM.BPM.AAAAAA.000.000
NEM.ESB.ZZZ.999.999
NEM.BPM.ZZZ.999.999
NEM.ESB.ZZZZZZ.999.999
NEM.BPM.ZZZZZZ.999.999
ANEM.ESB.TST.400.1
AEM.BPM.TST.400.1
AEM.ESB.TSTTST.400.1
AEM.BPM.TSTTST.400.1
AEM.ESB.TST.400.001
AEM.BPM.TST.400.001
AEM.ESB.TSTTST.400.001
AEM.BPM.TSTTST.400.001
AEM.ESB.AAA.000.000
AEM.BPM.AAA.000.000
AEM.ESB.AAAAAA.000.000
AEM.BPM.AAAAAA.000.000
AEM.ESB.ZZZ.999.999
AEM.BPM.ZZZ.999.999
AEM.ESB.ZZZZZZ.999.999
AEM.BPM.ZZZZZZ.999.999
`;
// 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