const regex = /^\d{1,2}([ -.\/])(\d{1,2}|[a-zA-z]{3,15})(?1)\d{2,4}( \d{2}:\d{2}(:\d{2}([.:]\d)?)?)?$|^(\d{1,2}|[a-zA-z]{3,15})([ -.\/])\d{1,2}(?7)\d{2,4}( \d{2}:\d{2}(:\d{2}([.:]\d)?)?)?$|^\d{2,4}([ -.\/])(\d{1,2}|[a-zA-z]{3,15})\d{1,2}(?11)( \d{2}:\d{2}(:\d{2}([.:]\d)?)?)?$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^\\d{1,2}([ -.\\\/])(\\d{1,2}|[a-zA-z]{3,15})(?1)\\d{2,4}( \\d{2}:\\d{2}(:\\d{2}([.:]\\d)?)?)?$|^(\\d{1,2}|[a-zA-z]{3,15})([ -.\\\/])\\d{1,2}(?7)\\d{2,4}( \\d{2}:\\d{2}(:\\d{2}([.:]\\d)?)?)?$|^\\d{2,4}([ -.\\\/])(\\d{1,2}|[a-zA-z]{3,15})\\d{1,2}(?11)( \\d{2}:\\d{2}(:\\d{2}([.:]\\d)?)?)?$', 'gm')
const str = `23/02/1993
23-02/1993
23-fev-1993
fev-23-1993
fev.02.93
28-OCT-90
28-OCT-1990
10/28/90
10/28/1990
28.10.90
dd.mm.yyyy
28.10.1990
90/10/28
yyyy/mm/dd
1990/10/28
4 Q 1990
OCT 90
OCT 1990
01:02
01:02:34.75
02:34
02:34.75
20 08:03
20 08:03:00
20-JUN-1990 08:03
20-JUN-1990 08:03:00
1990-06-20 08:03
1990-06-20 08:03:00.0`;
// 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