const regex = /(.+\n.+\n)(\d+\.\d{1,2})/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(.+\\n.+\\n)(\\d+\\.\\d{1,2})', 'gm')
const str = `RETAIL
UPRICE QTY TOTAL
ILLUSTRATION BOARD 15X20 (1/4 SIZE ) BY
1276
12.50 1.0 12.50
MONGOL PENCIL 1,2,3 PC
434
6.50 1.0 6.50
MS 300 (MGK) PERMANENT MARKER
1470
3.75 1.0 3.75
HBW White Glue 40 grans
1690
10.00 1.0 10.00
COLOR PEN 8 COLORS (VARIOUS BRAND)
1930
16.50 1.0 16.50
KS /CREATION CONSTRUCTION PAPER (105)
3503
23.00 1.0 23.00`;
// 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