What is the good solution for extracting a date which is given in a string?
For example:
string block = "This should try to get a date 2005-10-26";
//TODO! I WANT THE DATE
Any good tips for me?
Regex maybe?
What is the good solution for extracting a date which is given in a string?
For example:
string block = "This should try to get a date 2005-10-26";
//TODO! I WANT THE DATE
Any good tips for me?
Regex maybe?
The simplest regex would be
but this doesn't do any error checking and only finds exactly that format.
If you want to do date validation, regex is not your best friend here. It's possible, but best left to a date parser, unless you want render suicidal whoever has to read your code six months from now. I would agree to a basic sanity check, but don't attempt to validate leap years etc.: