can anyone tell me what will be the regular expression of开发者_如何学Go the following:
yyyy-mm-dd(space)hr:i:s
e.g., exactly this format:
2001-07-31 22:05:00
I have to put this reg expression in ‘regex’
Depending on the regex library:
\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}
(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})
Parenthesis are if you want to catch the values of year, month etc.
Something like this:
[12][0-9]{3}-[01][0-9]-[0-3][0-9]\s[0-2][0-9]:[0-5][0-9]:[0-5][0-9]
(with some very basic validation for invalid input like 9999-99-99 99:99:99)
matches a date in yyyy-mm-dd format from between 1900-01-01 and 2099-12-31
^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$
精彩评论