const regex = /(((((0[1-9]|[1-2][0-9]|30)-(0[13-9]|1[0-2]))|((0[1-9]|1[0-9]|2[0-8])-02)|(31-(0[13578]|1[02])))-\d{4})|(29-02-((\d{2}(([2468]0)|([02468][48])|([13579][26])))|((([02468][048])|([13579][26]))0{2}))))/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(((((0[1-9]|[1-2][0-9]|30)-(0[13-9]|1[0-2]))|((0[1-9]|1[0-9]|2[0-8])-02)|(31-(0[13578]|1[02])))-\\d{4})|(29-02-((\\d{2}(([2468]0)|([02468][48])|([13579][26])))|((([02468][048])|([13579][26]))0{2}))))', 'gm')
const str = `28-01-0001
28-02-0001
28-03-0001
28-04-0001
28-05-0001
28-06-0001
28-07-0001
28-08-0001
28-09-0001
28-10-0001
28-11-0001
28-12-0001
29-01-0001
29-02-0001
29-03-0001
29-04-0001
29-05-0001
29-06-0001
29-07-0001
29-08-0001
29-09-0001
29-10-0001
29-11-0001
29-12-0001
30-01-0001
30-02-0001
30-03-0001
30-04-0001
30-05-0001
30-06-0001
30-07-0001
30-08-0001
30-09-0001
30-10-0001
30-11-0001
30-12-0001
31-01-0001
31-02-0001
31-03-0001
31-04-0001
31-05-0001
31-06-0001
31-07-0001
31-08-0001
31-09-0001
31-10-0001
31-11-0001
31-12-0001
29-02-0001
29-02-0002
29-02-0003
29-02-0004
29-02-0005
29-02-0006
29-02-0007
29-02-0008
29-02-0009
29-02-0010
29-02-0020
29-02-0030
29-02-0040
29-02-0050
29-02-0060
29-02-0070
29-02-0080
29-02-0090
29-02-0100
29-02-0110
29-02-0120
29-02-0130
29-02-0140
29-02-0150
29-02-0160
29-02-0170
29-02-0180
29-02-0190
29-02-0200
29-02-0300
29-02-0400
29-02-0500
29-02-0600
29-02-0700
29-02-0800
29-02-0900
29-02-1000
29-02-1100
29-02-1200
29-02-1300
29-02-1400
29-02-1500
29-02-1600
29-02-1700
29-02-1800
29-02-1900
29-02-2000`;
// 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