$re = '/(((20[012]\d|19\d\d)|(1\d|2[0123]))-((0[0-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01])))|(((0[1-9])|([12][0-9])|(3[01]))-((0[0-9])|(1[012]))-((20[012]\d|19\d\d)|(1\d|2[0123])))|(((20[012]\d|19\d\d)|(1\d|2[0123]))\/((0[0-9])|(1[012]))\/((0[1-9])|([12][0-9])|(3[01])))|(((0[0-9])|(1[012]))\/((0[1-9])|([12][0-9])|(3[01]))\/((20[012]\d|19\d\d)|(1\d|2[0123])))|(((0[1-9])|([12][0-9])|(3[01]))\/((0[0-9])|(1[012]))\/((20[012]\d|19\d\d)|(1\d|2[0123])))|(((0[1-9])|([12][0-9])|(3[01]))\.((0[0-9])|(1[012]))\.((20[012]\d|19\d\d)|(1\d|2[0123])))|(((20[012]\d|19\d\d)|(1\d|2[0123]))\.((0[0-9])|(1[012]))\.((0[1-9])|([12][0-9])|(3[01])))/m';
$str = 'work:
2022-01-01
01-01-2020
1990/01/01
12/30/2020
30/12/2020
30.12.2020
2020.12.30
19-12-30
30-12-19
2020/12/30
12/30/19
30/12/19
30.12.19
19.12.30
not work:
1022-01-01
01-15-2020
2990/01/01
13/30/2020
30/13/2020
30.12.9029
2020.14.30
2020.12.33
19-12-33
19-13-30
33-12-19
30-12-35
2020/13/30
2020/12/34
12/30/29
30/12/29
30.12.26
30.12.30
13/30/19
30/13/19
30.13.19
19.13.30
12/33/19
33/12/19
33.12.19
19.12.33
1/1/19
1/01/19
01/1/19
1/01/2019
1/1/2019
01/1/2019
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php