const regex = /^\s{8,9}\d{1,2}\s{2}\|\s{9,10}\d{1,2}\s{2}\|\s{9,10}\d{1,2}$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^\\s{8,9}\\d{1,2}\\s{2}\\|\\s{9,10}\\d{1,2}\\s{2}\\|\\s{9,10}\\d{1,2}$', 'gm')
const str = ` 12 | 11 | 5
13 | 3 | 13
5 | 16 | 3
15 | 2 | 20
8 | 5 | 16
4 | 12 | 3
20 | 1 | 14
9 | 1 | 1
15 | 13 | 14
15 | 1 | 1
18 | 15 | 5
5 | 1 | 18
13 | 9 | 8
16 | 1 | 1
5 | 5 | 14
7 | 17 | 10
8 | 13 | 20
12 | 2 | 20
8 | 14 | 3
14 | 11 | 18
6 | 11 | 14
19 | 12 | 3
8 | 7 | 13
8 | 3 | 20`;
// 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