const regex = /^[A-Z\d]+\s+\d{4}-\d{2}-\d{2}\s+\w+(?:[ -]\w+)*\s+\S+\s+\S+\s+(\S+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^[A-Z\\d]+\\s+\\d{4}-\\d{2}-\\d{2}\\s+\\w+(?:[ -]\\w+)*\\s+\\S+\\s+\\S+\\s+(\\S+)', 'gm')
const str = `2020-08-26 PILE OF LIFE HEALTH PRODUCTS LP Page 1 A/P Remittance Advice Direct Deposit 2020-08-26
Cheque # 11361 Vendor # 0828 HAIN CELESTIAL CANADA, ULC
Invoice # Date Description Gross Disc Net
===============================================================
225299 2020-07-24 P2156678 7,610.52 .00 7,610.52
225839 2020-07-22 P2157105 7,826.28 .00 7,826.28
225969 2020-07-22 P2157106 8,760.59 .00 8,760.59
226384 2020-07-22 P2157104 42,274.76 .00 42,274.76
CR01BEPJ 2020-08-17 MULTI MCBS 4,470.06- .00 4,470.06-
CR01BEXS 2020-08-24 MULTI MCBS 5,212.81- .00 5,212.81-
DM20082311 2020-08-14 LIFESTYLE MARKETS NA 201.25- .00 201.25-
DM20083583 2020-08-17 KARDISH FOOD FRANCHI 281.37- .00 281.37-
DM20085965 2020-08-12 AVRILSUPERMARCHE-WAR 871.50- .00 871.50-
DM20086678 2020-08-12 AVRILSUPERMARCHE-WAR 871.50- .00 871.50-
DM20089459 2020-07-30 LOBLAWS 8.90- .00 8.90-
DM20089500 2020-08-14 COUNTRY GROCER-CHASE 105.00- .00 105.00-
========================================== 54,449.76 .00 54,449.76
Printed on 2020-08-26 at 6:26
2020-04-23 PILE OF LIFE HEALTH PRODUCTS LP Page 1 A/P Remittance Advice Direct Deposit 2020-04-23
Cheque # 9699 Vendor # 0828 HAIN CELESTIAL CANADA, ULC
Invoice # Date Description Gross Disc Net ===================================================================================
218124 2020-02-27 P2151168 2,253.44 .00 2,253.44
219021 2020-03-18 P2152030 35,242.65 .00 35,242.65
219216 2020-03-18 P2152031 8,306.81 .00 8,306.81
CR01BASW 2020-04-20 MULTI MCBS 5,278.05- .00 5,278.05-
DM2004W450 2020-04-17 RETURNS WFM-GR-20589 124.63- .00 124.63-
DM2004W828 2020-04-17 RETURNS WFM-GR-20589 266.09- .00 266.09-
DM20042157 2020-04-07 AVRIL 871.50- .00 871.50-
DM20043798 2020-04-07 COUNTRY GROCER 105.00- .00 105.00-
DM20043892 2020-04-07 COUNTRY GROCER 105.00- .00 105.00-
DM20048663 2020-04-07 AVRIL 871.50- .00 871.50-
DM20049986 2020-04-02 LA MOISSON 258.69- .00 258.69-
========================================== 37,922.44 .00 37,922.44
Printed on 2020-04-23 at 13:13`;
// 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