const regex = /(\d{3}\s\d{3}\s\d{3}\s\d{3})\s+(.+?)\s+(\d{2}\/\d{2}\/\d{4})\s+(\d+,\d+)\s+([\d,]+\s[€$£])\s+([\d,]+\s[€$£])\s+(\d+,\d+%)\s+([\d,]+\s[€$£])/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\d{3}\\s\\d{3}\\s\\d{3}\\s\\d{3})\\s+(.+?)\\s+(\\d{2}\\\/\\d{2}\\\/\\d{4})\\s+(\\d+,\\d+)\\s+([\\d,]+\\s[€$£])\\s+([\\d,]+\\s[€$£])\\s+(\\d+,\\d+%)\\s+([\\d,]+\\s[€$£])', 'gm')
const str = `janvier 2024\\n54 \\n31/01/2024\\nMontant HT TVA Montant TTC\\nTotal TVA 5,50% \\n9 799,13 € \\n5,50% \\n10 338,09 €\\nTotal TVA 20,00% \\n10 973,38 € \\n20,00% \\n13 168,07 €\\nTotal 20 772,51 € 23 506,16 €\\nCode Affaire Désignation Commande Unité Tarif Montant HT TVA Montant TTC\\n117 253 668 000 Pack Colorie et Décore LOL (M01172-1) 31/01/2024 668,000 2,496 € 1 667,33 € 20,00% 2 000,80 €\\n212 153 668 000 Coffret créatif LOL XS (M02121-1) 31/01/2024 265,000 3,329 € 882,19 € 20,00% 1 058,63 €\\n438 653 668 000 Pochette dinosaures (M04386-1) 31/01/2024 225,000 2,079 € 467,78 € 20,00% 561,34 €\\n499 253 668 000 Pochette activités Girly (M04992-1) 31/01/2024 1 028,000 2,839 € 2 918,49 € 5,50% 3 079,01 €\\n499 753 668 000 Mon carnet fantaisie (M04997-1) 31/01/2024 1 459,000 4,716 € 6 880,64 € 5,50% 7 259,08 €\\n503 853 668 000 Coffret créatif Licorne XS (M05038-1) 31/01/2024 991,000 3,329 € 3 299,04 € 20,00% 3 958,85 €\\n504 153 664 000 Coffret créatif Licorne Emoji (M05041-1) 31/01/2024 434,000 4,162 € 1 806,31 € 20,00% 2 167,57 €\\n508 253 668 000 Coffret créatif LOL XL (M05082-1) 31/01/2024 524,000 4,162 € 2 180,89 € 20,00% 2 617,07 €\\n528 353 668 000 Set papeterie LOL (M05283-1) 31/01/2024 99,000 1,663 € 164,64 € 20,00% 197,57 €\\n528 653 668 000 Stylos gel LOL (M05286-1) 31/01/2024 243,000 2,079 € 505,20 € 20,00% 606,24 €\\nFACTURES\\nRelevé de vente à facturer\\nPage 1 de 1`;
// 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