$re = '/(?:18|19|20)\d{2}(-(?:00|0[1-9]|1[012])(-(?:00|(?:(?<!00-)0[1-9]|[12]\d|3[01])))?)?/m';
$str = 'Jahr bekannt
2023-00-00
2023-00
2023
Monat bekannt
2023-01-00
2023-01-00
2023-02-00
2023-03-00
2023-04-00
2023-05-00
2023-06-00
2023-07-00
2023-08-00
2023-09-00
2023-10-00
2023-11-00
2023-12-00
2023-01
Tag bekannt
2023-01-01
ungültig
2023-00-01
2023-01-32
2023-13
1799-11-07';
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