<span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: 16px; "><div style="margin-top: 8px; margin-right: 8px; margin-bottom: 8px; margin-left: 8px; font: normal normal normal small/normal arial; ">

<div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">I am writing a regex to test for valid dates in YYYY-MM-DD format.</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"><br></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">Using this regex in a perl test program I get positive results for all dates for the next 365 days.  </span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"><br></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">Regex Coach however failes to match some such as '2010-06-30'.  I assume this is because of the  order of the alternations and the regex wanting to match a sub-pattern as quickly as possible.  I can resolve the issue in The Regex Coach by adding () around the month and year patterns.</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small; "><br></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">I would like to know why there is a difference between my Perl program and Regex Coach.  Could this be implementation dependent.  Both my program and its output are below.</span></font></div>

<div><font class="Apple-style-span" face="'courier new'" size="2"><span class="Apple-style-span" style="font-size: 10px;"><br></span></font></div><div><font class="Apple-style-span" face="'courier new'" size="2"><span class="Apple-style-span" style="font-size: 10px;">I tend to think that The Regex Coach got this right.</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small; "><br></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">(?# regex in The Regex Coach)</span></font></div>

<div><b><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">        [123456789]\d\d\d-                                           # year</span></font></b></div>

<div><b><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">         (?:                                                      </span></font></b></div>

<div><b><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">            (?:0[13578]|10|12 -  [012][123456789]|10|20|30|31)  |      # Months with 31 days</span></font></b></div>

<div><b><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">            (?:0[469]|11      -  [012][123456789]|10|20|30   )  |      # Months with 30 days  </span></font></b></div>

<div><b><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">            (?:02             -  [012][12345678]||10|20|19   )         # Febuary</span></font></b></div>

<div><b><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">         )</span></font></b></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"><br>

</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">### perl Test program</span></font></div><div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">#!/iw-home/teamsite/iw-perl/bin/iwperl</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"><br></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">use strict;</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">use warnings;</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">use Carp;</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">use Getopt::Long;</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">use Pod::Usage;</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">use Cwd;</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">use Date::Calc qw(:all);</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"><br></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">my $dateregex = qr{</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">        [123456789]\d\d\d-                                           # year</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">         (?:                                                      </span></font></div><div>

<font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">            (?:0[13578]|10|12 -  [012][123456789]|10|20|30|31)  |      # Months with 31 days</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">            (?:0[469]|11      -  [012][123456789]|10|20|30   )  |      # Months with 30 days  </span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">            (?:02             -  [012][12345678]||10|20|19   )         # Febuary</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">         )</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">}smx;</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"><br></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">sub testdate {</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">    my ($d) = (@_);</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">    print "$d";</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">    if ( $d =~ m{$dateregex}smx ) {</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">        print "okay\n";</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">    }</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">    else {</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">        print "\n";</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">        croak "broken";</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">    }</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">}</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"><br></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">foreach my $d ( 1 .. 365 ) {</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">    my ( $year, $month, $day, $hour, $min, $sec, $doy, $dow, $dst ) =</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">      System_Clock();</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">    ( $year, $month, $day, $hour, $min, $sec ) =</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">      Add_Delta_DHMS( $year, $month, $day, '0', '0', '0', "$d", '0', '0', '0' );</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"><br></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">    my $td = sprintf( "%4d-%02d-%02d", $year, $month, $day );</span></font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">    testdate("$td");</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"><br>

</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">}</span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">exit;</span></font></div>

<div><br></div><div><br></div><div>##OUTPUT</div><div><div>2009-08-03okay</div><div>2009-08-04okay</div><div>2009-08-05okay</div><div>2009-08-06okay</div><div>2009-08-07okay</div><div>2009-08-08okay</div><div>2009-08-09okay</div>

<div>2009-08-10okay</div><div>2009-08-11okay</div><div>2009-08-12okay</div><div>2009-08-13okay</div><div>2009-08-14okay</div><div>2009-08-15okay</div><div>2009-08-16okay</div><div>2009-08-17okay</div><div>2009-08-18okay</div>

<div>2009-08-19okay</div><div>2009-08-20okay</div><div>2009-08-21okay</div><div>2009-08-22okay</div><div>2009-08-23okay</div><div>2009-08-24okay</div><div>2009-08-25okay</div><div>2009-08-26okay</div><div>2009-08-27okay</div>

<div>2009-08-28okay</div><div>2009-08-29okay</div><div>2009-08-30okay</div><div>2009-08-31okay</div><div>2009-09-01okay</div><div>2009-09-02okay</div><div>2009-09-03okay</div><div>2009-09-04okay</div><div>2009-09-05okay</div>

<div>2009-09-06okay</div><div>2009-09-07okay</div><div>2009-09-08okay</div><div>2009-09-09okay</div><div>2009-09-10okay</div><div>2009-09-11okay</div><div>2009-09-12okay</div><div>2009-09-13okay</div><div>2009-09-14okay</div>

<div>2009-09-15okay</div><div>2009-09-16okay</div><div>2009-09-17okay</div><div>2009-09-18okay</div><div>2009-09-19okay</div><div>2009-09-20okay</div><div>2009-09-21okay</div><div>2009-09-22okay</div><div>2009-09-23okay</div>

<div>2009-09-24okay</div><div>2009-09-25okay</div><div>2009-09-26okay</div><div>2009-09-27okay</div><div>2009-09-28okay</div><div>2009-09-29okay</div><div>2009-09-30okay</div><div>2009-10-01okay</div><div>2009-10-02okay</div>

<div>2009-10-03okay</div><div>2009-10-04okay</div><div>2009-10-05okay</div><div>2009-10-06okay</div><div>2009-10-07okay</div><div>2009-10-08okay</div><div>2009-10-09okay</div><div>2009-10-10okay</div><div>2009-10-11okay</div>

<div>2009-10-12okay</div><div>2009-10-13okay</div><div>2009-10-14okay</div><div>2009-10-15okay</div><div>2009-10-16okay</div><div>2009-10-17okay</div><div>2009-10-18okay</div><div>2009-10-19okay</div><div>2009-10-20okay</div>

<div>2009-10-21okay</div><div>2009-10-22okay</div><div>2009-10-23okay</div><div>2009-10-24okay</div><div>2009-10-25okay</div><div>2009-10-26okay</div><div>2009-10-27okay</div><div>2009-10-28okay</div><div>2009-10-29okay</div>

<div>2009-10-30okay</div><div>2009-10-31okay</div><div>2009-11-01okay</div><div>2009-11-02okay</div><div>2009-11-03okay</div><div>2009-11-04okay</div><div>2009-11-05okay</div><div>2009-11-06okay</div><div>2009-11-07okay</div>

<div>2009-11-08okay</div><div>2009-11-09okay</div><div>2009-11-10okay</div><div>2009-11-11okay</div><div>2009-11-12okay</div><div>2009-11-13okay</div><div>2009-11-14okay</div><div>2009-11-15okay</div><div>2009-11-16okay</div>

<div>2009-11-17okay</div><div>2009-11-18okay</div><div>2009-11-19okay</div><div>2009-11-20okay</div><div>2009-11-21okay</div><div>2009-11-22okay</div><div>2009-11-23okay</div><div>2009-11-24okay</div><div>2009-11-25okay</div>

<div>2009-11-26okay</div><div>2009-11-27okay</div><div>2009-11-28okay</div><div>2009-11-29okay</div><div>2009-11-30okay</div><div>2009-12-01okay</div><div>2009-12-02okay</div><div>2009-12-03okay</div><div>2009-12-04okay</div>

<div>2009-12-05okay</div><div>2009-12-06okay</div><div>2009-12-07okay</div><div>2009-12-08okay</div><div>2009-12-09okay</div><div>2009-12-10okay</div><div>2009-12-11okay</div><div>2009-12-12okay</div><div>2009-12-13okay</div>

<div>2009-12-14okay</div><div>2009-12-15okay</div><div>2009-12-16okay</div><div>2009-12-17okay</div><div>2009-12-18okay</div><div>2009-12-19okay</div><div>2009-12-20okay</div><div>2009-12-21okay</div><div>2009-12-22okay</div>

<div>2009-12-23okay</div><div>2009-12-24okay</div><div>2009-12-25okay</div><div>2009-12-26okay</div><div>2009-12-27okay</div><div>2009-12-28okay</div><div>2009-12-29okay</div><div>2009-12-30okay</div><div>2009-12-31okay</div>

<div>2010-01-01okay</div><div>2010-01-02okay</div><div>2010-01-03okay</div><div>2010-01-04okay</div><div>2010-01-05okay</div><div>2010-01-06okay</div><div>2010-01-07okay</div><div>2010-01-08okay</div><div>2010-01-09okay</div>

<div>2010-01-10okay</div><div>2010-01-11okay</div><div>2010-01-12okay</div><div>2010-01-13okay</div><div>2010-01-14okay</div><div>2010-01-15okay</div><div>2010-01-16okay</div><div>2010-01-17okay</div><div>2010-01-18okay</div>

<div>2010-01-19okay</div><div>2010-01-20okay</div><div>2010-01-21okay</div><div>2010-01-22okay</div><div>2010-01-23okay</div><div>2010-01-24okay</div><div>2010-01-25okay</div><div>2010-01-26okay</div><div>2010-01-27okay</div>

<div>2010-01-28okay</div><div>2010-01-29okay</div><div>2010-01-30okay</div><div>2010-01-31okay</div><div>2010-02-01okay</div><div>2010-02-02okay</div><div>2010-02-03okay</div><div>2010-02-04okay</div><div>2010-02-05okay</div>

<div>2010-02-06okay</div><div>2010-02-07okay</div><div>2010-02-08okay</div><div>2010-02-09okay</div><div>2010-02-10okay</div><div>2010-02-11okay</div><div>2010-02-12okay</div><div>2010-02-13okay</div><div>2010-02-14okay</div>

<div>2010-02-15okay</div><div>2010-02-16okay</div><div>2010-02-17okay</div><div>2010-02-18okay</div><div>2010-02-19okay</div><div>2010-02-20okay</div><div>2010-02-21okay</div><div>2010-02-22okay</div><div>2010-02-23okay</div>

<div>2010-02-24okay</div><div>2010-02-25okay</div><div>2010-02-26okay</div><div>2010-02-27okay</div><div>2010-02-28okay</div><div>2010-03-01okay</div><div>2010-03-02okay</div><div>2010-03-03okay</div><div>2010-03-04okay</div>

<div>2010-03-05okay</div><div>2010-03-06okay</div><div>2010-03-07okay</div><div>2010-03-08okay</div><div>2010-03-09okay</div><div>2010-03-10okay</div><div>2010-03-11okay</div><div>2010-03-12okay</div><div>2010-03-13okay</div>

<div>2010-03-14okay</div><div>2010-03-15okay</div><div>2010-03-16okay</div><div>2010-03-17okay</div><div>2010-03-18okay</div><div>2010-03-19okay</div><div>2010-03-20okay</div><div>2010-03-21okay</div><div>2010-03-22okay</div>

<div>2010-03-23okay</div><div>2010-03-24okay</div><div>2010-03-25okay</div><div>2010-03-26okay</div><div>2010-03-27okay</div><div>2010-03-28okay</div><div>2010-03-29okay</div><div>2010-03-30okay</div><div>2010-03-31okay</div>

<div>2010-04-01okay</div><div>2010-04-02okay</div><div>2010-04-03okay</div><div>2010-04-04okay</div><div>2010-04-05okay</div><div>2010-04-06okay</div><div>2010-04-07okay</div><div>2010-04-08okay</div><div>2010-04-09okay</div>

<div>2010-04-10okay</div><div>2010-04-11okay</div><div>2010-04-12okay</div><div>2010-04-13okay</div><div>2010-04-14okay</div><div>2010-04-15okay</div><div>2010-04-16okay</div><div>2010-04-17okay</div><div>2010-04-18okay</div>

<div>2010-04-19okay</div><div>2010-04-20okay</div><div>2010-04-21okay</div><div>2010-04-22okay</div><div>2010-04-23okay</div><div>2010-04-24okay</div><div>2010-04-25okay</div><div>2010-04-26okay</div><div>2010-04-27okay</div>

<div>2010-04-28okay</div><div>2010-04-29okay</div><div>2010-04-30okay</div><div>2010-05-01okay</div><div>2010-05-02okay</div><div>2010-05-03okay</div><div>2010-05-04okay</div><div>2010-05-05okay</div><div>2010-05-06okay</div>

<div>2010-05-07okay</div><div>2010-05-08okay</div><div>2010-05-09okay</div><div>2010-05-10okay</div><div>2010-05-11okay</div><div>2010-05-12okay</div><div>2010-05-13okay</div><div>2010-05-14okay</div><div>2010-05-15okay</div>

<div>2010-05-16okay</div><div>2010-05-17okay</div><div>2010-05-18okay</div><div>2010-05-19okay</div><div>2010-05-20okay</div><div>2010-05-21okay</div><div>2010-05-22okay</div><div>2010-05-23okay</div><div>2010-05-24okay</div>

<div>2010-05-25okay</div><div>2010-05-26okay</div><div>2010-05-27okay</div><div>2010-05-28okay</div><div>2010-05-29okay</div><div>2010-05-30okay</div><div>2010-05-31okay</div><div>2010-06-01okay</div><div>2010-06-02okay</div>

<div>2010-06-03okay</div><div>2010-06-04okay</div><div>2010-06-05okay</div><div>2010-06-06okay</div><div>2010-06-07okay</div><div>2010-06-08okay</div><div>2010-06-09okay</div><div>2010-06-10okay</div><div>2010-06-11okay</div>

<div>2010-06-12okay</div><div>2010-06-13okay</div><div>2010-06-14okay</div><div>2010-06-15okay</div><div>2010-06-16okay</div><div>2010-06-17okay</div><div>2010-06-18okay</div><div>2010-06-19okay</div><div>2010-06-20okay</div>

<div>2010-06-21okay</div><div>2010-06-22okay</div><div>2010-06-23okay</div><div>2010-06-24okay</div><div>2010-06-25okay</div><div>2010-06-26okay</div><div>2010-06-27okay</div><div>2010-06-28okay</div><div>2010-06-29okay</div>

<div>2010-06-30okay</div><div>2010-07-01okay</div><div>2010-07-02okay</div><div>2010-07-03okay</div><div>2010-07-04okay</div><div>2010-07-05okay</div><div>2010-07-06okay</div><div>2010-07-07okay</div><div>2010-07-08okay</div>

<div>2010-07-09okay</div><div>2010-07-10okay</div><div>2010-07-11okay</div><div>2010-07-12okay</div><div>2010-07-13okay</div><div>2010-07-14okay</div><div>2010-07-15okay</div><div>2010-07-16okay</div><div>2010-07-17okay</div>

<div>2010-07-18okay</div><div>2010-07-19okay</div><div>2010-07-20okay</div><div>2010-07-21okay</div><div>2010-07-22okay</div><div>2010-07-23okay</div><div>2010-07-24okay</div><div>2010-07-25okay</div><div>2010-07-26okay</div>

<div>2010-07-27okay</div><div>2010-07-28okay</div><div>2010-07-29okay</div><div>2010-07-30okay</div><div>2010-07-31okay</div><div>2010-08-01okay</div><div>2010-08-02okay</div></div></div></div></div></span>