const regex = new RegExp('(?<!d)(?:
(?:(?:0?[1-9]|[12]\\d)|3[01])\\s?[./:-][\\s.]?(?:0?[13578]|1[02]|J(?:an(?:uar)?|uli?)|M(?:ärz?|ai)|Aug(?:ust)?|Dez(?:ember)?|Okt(?:ober)?)\\s?(?:[./:-][\\s.]?)?[1-9]\\d\\d\\d|
(?:(?:0?[1-9]|[12]\\d)|30)\\s?[./:-][\\s.]?(?:0?[13-9]|1[012]|J(?:an(?:uar)?|u[nl]i?)|M(?:ärz?|ai)|A(?:pr(?:il)?|ug(?:ust)?)|Sep(?:tember)?|(?:Nov|Dez)(?:ember)?|Okt(?:ober)?)\\s?(?:[./:-][\\s.]?)?[1-9]\\d\\d\\d|
(?:0?[1-9]|[12]\\d)\\s?[./:-][\\s.]?(?:0?2|Fe(?:b(?:ruar)?)?)\\s?(?:[./:-][\\s.]?)?[1-9]\\d(?:[02468][048]|[13579][26])|
(?:0?[1-9]|[12][0-8])\\s?[./:-][\\s.]?(?:0?2|Fe(?:b(?:ruar)?)?)\\s?(?:[./:-][\\s.]?)?[1-9]\\d\\d\\d
)(?!\\d)', 'gm')
const str = `12.12.2021
09. Juni 1997
01.Aug.1995
27.06. 1997
29.02.1996
21. 01. 1999
28.05. 1996
07..4..1995
20:03:1998
9.4.1997
14 .03 - 1995
Month regex is tested at https://regex101.com/r/tClRRs/2
(?:J(?:an(?:uar)?|u[nl]i?)|Fe(?:b(?:ruar)?)?|M(?:ärz?|ai)|A(?:pr(?:il)?|ug(?:ust)?)|Sep(?:tember)?|(?:Nov|Dez)(?:ember)?|Okt(?:ober)?)
Taking out Feb: (?:J(?:an(?:uar)?|u[nl]i?)|M(?:ärz?|ai)|A(?:pr(?:il)?|ug(?:ust)?)|Sep(?:tember)?|(?:Nov|Dez)(?:ember)?|Okt(?:ober)?)
`;
// 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