const regex = /(?<=[A-Z]{3}\s)\D+[\d/.\w]+\s?(\d{2}:\d{2})?/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<=[A-Z]{3}\\s)\\D+[\\d\/.\\w]+\\s?(\\d{2}:\\d{2})?', 'gm')
const str = `29 NOV VISA PURCHASE 27/11/16 59.99 2,405.99
30 NOV VISA PURCHASE 28/11/16 761.98 1,644.01
30 NOV VISA PURCHASE 29/11/16 822.00 822.01
02 DEC VISA PURCHASE 01/12/16 14.99 807.02
03 DEC VISA PURCHASE 01/12/16 5.50 801.52
27 NOV OPENING BALANCE 465.98
28 NOV INTERNET DEPOSIT 28NOV 13:38 1,000.00 1,465.98
30 NOV INTERNET DEPOSIT 29NOV`;
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