const regex = new RegExp('(?:(?P<EngDate>[a-zA-Z]+\\s)??(?P<Date0>(?<!\\.)(?:\\d{1,2}(?=[,\\s.\\/-])|\\d{4}))\\.??(?(1),?)(?P<d_sep>[\\s.\\/-])?(?:(?P<Date1>[^\\W\\d_]+|\\d{1,2})(?P=d_sep))?(?(1)[0-2]?\\d(?::\\d{2}){1,2}\\s\\w+\\s)(?P<Date2>\\d{2}|\\d{4})(?!:|\\d))|(?P<Time>(?<![\\+-0])[0-2]?\\d(?:\\:[0-6]\\d){1,2}(?:[,\\.]\\d{3,6})?)', 'g')
const str = `04.march.2012 9:07:00
1999-03-22T05:06:07.000
20150420
14 мая 2015 08:30:43
1999 03 22T05:06:07.000+01:00
22.3.1999 5:06:07
22. March 1999
1999-03-22 5:06:07.PD
March 22, 1999
March 22 1999
22/3/1999 5:06:07 AM
Mar 22 05:06:07 CET 1999`;
// 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