这个简单的怎么样:
^(?:[01]?\d|2[0-3]):[0-5]?\d$
解释:
The regular expression:
(?-imsx:^(?:[01]?\d|2[0-3]):[0-5]?\d$)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
[01]? any character of: '0', '1' (optional
(matching the most amount possible))
----------------------------------------------------------------------
\d digits (0-9)
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
2 '2'
----------------------------------------------------------------------
[0-3] any character of: '0' to '3'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
: ':'
----------------------------------------------------------------------
[0-5]? any character of: '0' to '5' (optional
(matching the most amount possible))
----------------------------------------------------------------------
\d digits (0-9)
----------------------------------------------------------------------
$ before an optional \n, and the end of the
string
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------