const regex = /^(?<Data_0>[ ]{13,16})(?<Data_1>[0-9]{6,9})\s{5,6}(?<Data_2>[0-9a-zA-Z\/.\-_,\n%: ]{6,720})(?: [0-9]{8} )/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?<Data_0>[ ]{13,16})(?<Data_1>[0-9]{6,9})\\s{5,6}(?<Data_2>[0-9a-zA-Z\\\/.\\-_,\\n%: ]{6,720})(?: [0-9]{8} )', 'gm')
const str = ` 6001908/ SAR - 125 KG 1 PC 96.00 12,000.00
32021000 BALSYN
73101090 INV. REF TAX INVOICE INV DT. QTY BILL RATE
ACTUAL RATE RATE DIFF
BASIC AMT DIFF C.GST 9% UT GST 9% TOTAL DIFF.
AMOUNT
1710125231 DH191012604017 29.10.2019 200 1,350.00
1,290.00 60.00 12
,000.00 1,080.00 1,080.00 14,160.00
1710125233 DH191012604018 29.10.2019 203 1,350.00
1,290.00 60.00 12
,180.00 1,096.20 1,096.20 14,372.40
TOTAL 403 24,180.00 2,176.20 2,176.20 28,532.40
73101090 200/210 LITRE NOMINAL CAPACITY NEW EMPTY
DRUMS MADE
FROM STEEL SHEET OF 1.25 MM NOMINAL
THICKNESS
COMPLETE WITH 50MM AND 20MM CLOSURE,
INTERNALLY
EPOXY COATED AS PER YOUR SPECIFICATION
`;
// 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