const regex = /(?<=Code:).*Distribution\s([\d.,]+)(?=\n)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<=Code:).*Distribution\\s([\\d.,]+)(?=\\n)', 'g')
const str = `Code: 210 - Test 1 - Distribution
267745 Vis - Branch Deposit 3/10/2021 2,000.00
468040 v- Branch Deposit 2/10/2021 1,700.00
586075 Visa 3/3/2021 555.48
502490 Vis 3/4/2021 1,835.51
403195 Vis 3/4/2021 2,033.56
500230 Vis 3/4/2021 651.29
Code: 210 - Test - Distribution 8,775.84
Code: 230 - Greenville - Distribution
853955 Clearing 2/1/2021 77.50`;
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