#!/usr/local/bin/perl -w use strict; # CCYY-MM-DD[tz] my $pat = qr /^-?\d{4,}-(0\d|1[0-2])-\d\d(Z?|([+|-]{0,1}[0-2]?\d:[0-5]\d)?)$/; while () { chomp; print "$_ ", /$pat/ ? "matches\n" : "does not match\n"; } __DATA__ 1968-04-02 -0045-01-01 11968-04-02 1968-04-02+05:00 1968-04-02Z invalids to follow 68-04-02 1968-4-2 1968/04/02 04-02-1968 1968-04-31 #### bash-2.03$ ./date_regex.pl 1968-04-02 matches -0045-01-01 matches 11968-04-02 matches 1968-04-02+05:00 matches 1968-04-02Z matches invalids to follow does not match 68-04-02 does not match 1968-4-2 does not match 1968/04/02 does not match 04-02-1968 does not match 1968-04-31 matches