const regex = new RegExp('(?s)^(?=.* ABN \\d{2}(?: \\d{3}){3}\\n(?P<products>.*\\n)Qty\\n).*\\n\\$\\d+\\.\\d{2}\\n(?P<subtotal>\\d+) +SUBTOTAL\\.*\\nTOTAL\\n\\$(?P<total>\\d+\\.\\d{2})\\n', '')
const str = `ㅎㅎ
Fresh Food
The fresh food people
5619 Lorem PH: 00 0000 0000
204 Some Road
TAX INVOICE - ABN 88 000 014 675
Gift Card Visa Varbl 20to500Dollars
Potato White Washed 2Kg
Nescafe Coffee Blend 43 50g
^HToblerone Milk Chocolate Bar 50g
^HOreo Cookie Original 133g
#M&Ms Crispy 145g
*HRed Rock Deli Portgse Chicken 150g
^HWrigleys Extra Pepprmint 14pc 27g(?.*
Qty
57.95
3.50
5.00
0.90
1.50
4.50
3.50
2 @ \$1.80
each
3.60
\$80.45
9 SUBTOTAL
TOTAL
\$80.45
REWARDS SAVINGS
\$10.00
Fresh Food
5619
Lorem`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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