Common regular expression of date and time

Source: Internet
Author: User
Tags regular expression

Common regular expression of date and time
A large number of date and time regular expression matching functions are added to the favorites below, including minute, time and second.


Regular expression (? N: ^ (? = D )((? <Day> 31 (?! (. 0? [1, 2469] | 11) | 30 (?!. 0? 2) | 29 (? (. 0? 2 )(? =. {3, 4} (1 [6-9] | [2-9] d) (0 [48] | [2468] [048] | [13579] [26]) | (16 | [2468] [048] | [3579] [26]) 00) | 0? [1-9] | 1d | 2 [0-8]) (? <Sep> [/.-]) (? <Month> 0? [1-9] | 1 [012]) 2 (? <Year> (1 [6-9] | [2-9] d) d {2 })(? :(? = X20d) x20 | $ ))? (? <Time> (0? [1-9] | 1 [012]) (: [0-5] d) {0, 2 }(? I: [AP] M) | ([01] d | 2 [0-3]) (: [0-5] d) {1, 2 })? $)
Match 31/12/2003 | 29/2/2004 23:59:59 PM |
Mismatch 12/31/2003 | 29/2/2003 |


Regular expression ^ (? :(? : 31 (/|-| .)(? : 0? [2, 13578] | 1 [02]) 1 | (? :(? : 29 | 30) (/|-| .)(? : 0? [1, 3-9] | 1 [0-2]) 2 ))(? :(? : 1 [6-9] | [2-9] d )? D {2}) $ | ^ (? : 29 (/|-|.) 0? 23 (? :(? :(? : 1 [6-9] | [2-9] d )? (? : 0 [48] | [2468] [048] | [13579] [26]) | (? :(? : 16 | [2468] [048] | [3579] [26]) $ | ^ (? : 0? [1-9] | 1d | 2 [0-8]) (/|-| .)(? :(? : 0? [1-9]) | (? : 1 [0-2]) 4 (? :(? : 1 [6-9] | [2-9] d )? D {2}) $
Matching 29/02/1972 | 5-9-98 | 10-11-2002
Mismatch 29/02/2003 | 12/13/2002 | 1-1-1500


Regular expression ^ (? :( (Jan (uary )? | Ma (r (ch )? | Y) | Jul (y )? | Aug (ust )? | Oct (ober )? | Dec (ember )?) 31) | (Jan (uary )? | Ma (r (ch )? | Y) | Apr (il )? | Ju (ly ?) | (Ne ?)) | Aug (ust )? | Oct (ober )? | (Sept | Nov | Dec) (ember )?) (0? [1-9] | ([12] d) | 30) | (Feb (ruary )? (0? [1-9] | 1d | 2 [0-8] | (29 (? =, (1 [6-9] | [2-9] d) (0 [48] | [2468] [048] | [13579] [26]) | (16 | [2468] [048] | [3579] [26 ))))))), (1 [6-9] | [2-9] d) d {2 }))
Matching Jan 1, 2003 | February 29,200 4 | November 02,320 2
Does not match Feb 29,200 3 | Apr 31,197 8 | jan 33,3333


Regular expression ^ ([0-1]? [0-9]) | ([2] [0-3]) :( [0-5]? [0-9]) ([0-5]? [0-9])? $
Match 10:26:59 | 22:01:15 |
Mismatch 24:10:25 | 13: 2: 60


Regular expression (? = D) ^ (? :(?! (? : 10D (? : 0? [5-9] | 1 [0-4]) D (? 1582) | (? : 0? 9D (? : 0? [3-9] | 1 [0-3]) D (? : 1752 )))((? : 0? [2, 13578] | 1 [02]) | (? : 0? [469] | 11 )(?! /31 )(?! -31 )(?!. 31) | (? : 0? 2 (? = .? (? :(? : 29 .(?! 000 [04] | (? :(? : 1 [^ 0-6] | [2468] [^ 048] | [3579] [^ 26 ))(? :(? :(? : Dd )(? : [02468] [048] | [13579] [26]) (?! X20BC) | (? : 00 (? : 42 | 3 [0369] | 2 [147] | 1 [258] | 09) x20BC) | (? : 0? 2 (? = .(? :(? : DD) | (? : [01] d) | (? : 2 [0-8]) ([-./]) (0? [1-9] | [12] d | 3 [01]) 2 (?! 0000 )((? = (? : 00 (? : 4 [0-5] | [0-3]? D) x20BC) | (? : D {4 }(?! X20BC) d {4 }(? : X20BC )?) (? : $ | (? = X20d) x20 ))? ((? :(? : 0? [1-9] | 1 [012]) (? : [0-5] d) {0, 2 }(? : X20 [aApP] [mM]) | (? : [01] d | 2 [0-3]) (? : [0-5] d) {1, 2 })? $
Match 11/24/0004 02:50:10 PM | 2.29.2008 |
Mismatch 12/33/1020 | 2/29/2005 | AM


Regular expression ^ ([0]? [1-9] | [1 | 2] [0-9] | [3] [0 | 1]) [./-] ([0]? [1-9] | [1] [0-2]) [./-] ([0-9] {4} | [0-9] {2}) $
Match 10/03/1979 | 1-1-02 | 01.1.2003
Mismatch 10/03/197 | 01 02 03


Regular expression ^ (0? [1, 13578] | 10 | 12) (-|/) ([1-9]) | (0 [1-9]) | ([12]) ([0-9]?) | (3 [01]?) (-|/) (19) ([2-9]) (d {1}) | (20) ([01]) (d {1 }) | ([2, 8901]) (d {1}) | (0? [2469] | 11) (-|/) ([1-9]) | (0 [1-9]) | ([12]) ([0-9]?) | (3 [0]?) (-|/) (19) ([2-9]) (d {1}) | (20) ([01]) (d {1 }) | ([1, 8901]) (d {1}) $
Match 1/2/03 | 02/30/1999 | 3/04/00
Unmatched 3/4/2020 | 3/4/1919 | 4/31/2000


Regular expression ^ ([2-9] d {3} (0 [1-9] | 1 [012]) (0 [1-9] | 1d | 2 [0-8]) | (0 [1, 13456789] | 1 [012]) (29 | 30) | (0 [1, 13578] | 1 [02]) 31) | ([2-9] d) (0 [48] | [2468] [048] | [13579] [26]) | ([2468] [048] | [3579] [26]) 00 )) 0229) $
Match 20000101 | 20051231 | 20040229
Mismatch 19990101 | 20053112 | 20050229


Regular expression ^ ([1-9] | 1 [0-2] | 0 [1-9]) {1 }(: [0-5] [0-9] [aApP] [mM]) {1} $
Match AM | am | pm
Does not match pm | 12: 65am


Regular expression ^ ([1-9]) | (0 [1-9]) | (1 [0-2])/([0-9]) | ([0-2] [0-9]) | (3 [0-1])/([0-9] [0-9]) | ([1-2] [0, 9] [0-9] [0-9]) $
Match 01/01/2001 | 1/1/1999 | 10/20/2080
Unmatched 13/01/2001 | 1/1/1800 | 10/32/2080


Regular expression ^ d {1, 2}/d {1, 2}/d {4} $
Matching 4/1/2001 | 12/12/2001 | 55/5/3434
Mismatch: 1/1/01 | 12 Jan 01 | 1-2001


Regular expression (d {2} | d {4 })(? :-)? ([0] {1} d {1} | [1] {1} [0-2] {1 })(? :-)? ([0-2] {1} d {1} | [3] {1} [0-1] {1 })(? : S )? ([0-1] {1} d {1} | [2] {1} [0-3] {1 })(? ::)? ([0-5] {1} d {1 })(? ::)? ([0-5] {1} d {1 })
Match 00-00-00 00:00:00 | 0000-00-00 00:00:00 | 09-05-22 08:16:00 | 00:00:00 | 20090522081600
Mismatch 2009-00:00:00 | 00:00:00 | 24:00:00 | 23: 60: 00 | 02-12-31 23: 00: 60


Regular expression ^ (? = D )(? :(?! (? 1582 (? :. |-|/) 10 (? :. |-| /)(? : 0? [5-9] | 1 [0-4]) | (? 1752 (? :. |-|/) 0? 9 (? :. |-| /)(? : 0? [3-9] | 1 [0-3]) (? = (? :(?! 000 [04] | (? :(? : 1 [^ 0-6] | [2468] [^ 048] | [3579] [^ 26 ))(? :(? : Dd )(? : [02468] [048] | [13579] [26]) D0? 2D29) | (? : D {4} D (?! (? : 0? [2469] | 11) D31 )(?! 0? 2 (? :. |-| /)(? : 29 | 30) (d {4}) ([-/.]) (0? D | 1 [012]) 2 ((?! 00) [012]? D | 3 [01]) (? : $ | (? = X20d) x20 ))? ((? :(? : 0? [1-9] | 1 [012]) (? : [0-5] d) {0, 2 }(? : X20 [aApP] [mM]) | (? : [01] d | 2 [0-3]) (? : [0-5] d) {1, 2 })? $
Match 0008-02-29 | 2:34:59 | 9999/12/31 PM
Mismatch 04/04/04 |


Regular expression ^ ([1-9] {1}) | ([0-1] [0-9]) | ([1-2] [0-3]) ([0-5] [0-9]) $
Match |
Mismatch | 00: 60 | 25: 61


Regular expression ^ [0-9] {4}-(0 [13578] | (10 | 12 )) -(0 [1-9] | [1-2] [0-9] | 3 [0-1]) | (02-(0 [1-9] | [1-2] [0-9]) | (0 [469] | 11) -(0 [1-9] | [1-2] [0-9] | 30) $
Match |
Mismatch |

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.