const regex = /DE\s+(3[01]|[12]\d|[1-9])\s+DE/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('DE\\s+(3[01]|[12]\\d|[1-9])\\s+DE', 'gm')
const str = `DE 1 DE
DE 2 DE
DE 3 DE
DE 4 DE
DE 5 DE
DE 6 DE
DE 7 DE
DE 8 DE
DE 9 DE
DE 10 DE
DE 11 DE
DE 12 DE
DE 13 DE
DE 14 DE
DE 15 DE
DE 16 DE
DE 17 DE
DE 18 DE
DE 19 DE
DE 20 DE
DE 21 DE
DE 22 DE
DE 23 DE
DE 24 DE
DE 25 DE
DE 26 DE
DE 27 DE
DE 28 DE
DE 29 DE
DE 30 DE
DE 31 DE
DE 32 DE
DE 0 DE
`;
// 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