title: Python Regex Date
body: <p>I'm trying create a regex that looks for all dates in the format MM-DD-YYYY, and this is what I came up with so far:</p>
  
  <pre><code>dateRegex = re.compile(r'''
              (0[1-9]|1[0-2])                  # Month 
              -                     
              (10|20|[0-2][1-9]|3[01])         # Day: not [0-2][0-9]|3[01] to avoid 00 matching 
              -
              ((198[0-9]|20(0[0-9]|1[0-6])'''  # Year: matches 1980 - 2016
              , re.VERBOSE)
  </code></pre>
  
  <p>Is there an easier way that allows me to create a range of numbers? And say I wanted to create one that only allows legal dates (for example, June shouldn't have 31 days), would the easiest way just be to match the months with different days, like:</p>
  
  <pre><code>((01|03|05|07|08|10|12)-(31 day regex pattern)-(year regex) # for 31-day months
  |
  (04|06|09|11)-(30 day regex pattern)-(year regex)           # for 30-day months
  |
  02-(regex depending on leap year))                          # 28 or 29 days
  </code></pre>
  
  <p>Not even sure how I would do the February besides putting all leaps years and 29 days together, and the remaining years with 28 days.</p>