const regex = /3\d{4}/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('3\\d{4}', 'gm')
const str = `AAXX 29224 03410 26768 82603 10106 20085 39676 40104 52008 88/// 333 55300 20000 60005 88/50 91004 90710 91106
BBXX VRPY6 25204 99304 50002 41397 50713 10160 20130 40250 54000 7//00 851// 22263 00190 21004 32323 41004 51004 6//// 80140 ICE /////`;
// 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