Q:

perl regular expression digit match

Doing the below regex match to verify whether date is in the YYYY_MM_DD Format. But the regular expression gives an error message if i have a value of 2012_07_7.  Date part and month should be exactly 2 digits according to the regex pattern. Not sure why it's not working.   
if ($cmdParams{RunId} !~ m/^\d{4}_\d{2}_\d{2}$/)
{
  print "Not a valid date in the format YYYY_MM_DD";
}

A:

Your regex specifies exactly 2 digits for the day component, if you want to allow either 1 or 2 digits you should use {1,2} rather than {2}

