const regex = /^(((.)(?=. \3))?(?=[0-8]?(\d? \d?)[1-9])(?=0?\4[1]|1\4?2|2\4?3|3\4?4|4\4?5|5\4?6|6\4?7|7\4?8|8\4?9|9\4?0).?9? ){98}99 100$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(((.)(?=. \\3))?(?=[0-8]?(\\d? \\d?)[1-9])(?=0?\\4[1]|1\\4?2|2\\4?3|3\\4?4|4\\4?5|5\\4?6|6\\4?7|7\\4?8|8\\4?9|9\\4?0).?9? ){98}99 100$', 'gm')
const str = `1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100`;
// 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