const regex = /\d{1,2}.\d{1,2}.20\d{2}/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\d{1,2}.\\d{1,2}.20\\d{2}', 'gm')
const str = `Example 1 (Colon)
Payee: John Smith
Account No: 145-567-981
Date: 19.01.2020
Time: 08:01
Email: JohnSmith@gmail.com
Example 2 (the dash)
John Smith - Payee
145 567 981 - Account No
19-01-2020 - Date
08:01 - Time
John.Smith@hotmail.com - Email
Example 3 (the dashes AND all one line of text)
Payee - John Smith - Account No - 145.567.9815 - Date - 19,1,2020 - Time - 08:01 - Email - John.Z.Smith@yahoo.com`;
// 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