The simplest regular expression would be
new Regex(@"\b\d{4}-\d{2}-\d{2}\b")
but it does not do any error checking and only finds this particular format.
If you want to check the date, regex is not your best friend here. It is possible, but it is best to leave the date parser if you do not want the suicidal person to read your code in six months. I would agree to a basic sanity check, but Iβm not trying to check leap years, etc .:
new Regex(@"\b\d{4}-(?:1[0-2]|0[1-9])-(?:3[01]|[12][0-9]|0[1-9])\b")
source share