Let's take a look at your regular expression first. Between the date and time when you match {\s}+ . This means "the symbol { followed by a space / tab followed by one or more } ".
Replace {\s} with ?:\s+ (non-capturing group matching one or more spaces / tabs), therefore full regex
^(\d{4})-(\d{2})-(\d{2})(?:\s+(\d{2}):(\d{2}):(\d{2}))?$
Demo
source share