title: Cannot operate on year value of regular expression
body: <p>This is my first question here so please forgive and educate on any formatting errors. I am new to Python and going through automate the boring stuff. Decided to expand the date detection project by using the clipboard and formatting some things also. The problem I have is in any operation taken on the year part of the REGEX.
  I have commented out my last attempt to validate the year and gave up and changed the REGEX to only find dates from 1000 to 2999 and skipped code validation of the dates.
  I now need to validate leap years but I'm back to having to work with the year variable, but once again no operation has any effect.
  Basically the problem is I can extract the year value and display it but I cannot modify it or do checks against it.</p>
  <pre><code>#! python3
  #! detect dates in a block of text
  
  import pyperclip
  import re
  
  #!import numpy as np
  
  
  text = str(pyperclip.paste())
  
  
  def datedetection(text):
  dateRegex = re.compile(
      r&quot;&quot;&quot;(
      (\d|\d\d)               #! match day
      (/{1})                  #! match /
      (\d|\d\d)               #! match month
      (/{1})                  #! match /
      ([1|2][0-9][0-9][0-9])  #! match year
      )&quot;&quot;&quot;,
      re.VERBOSE,
  )
  matches = []
  for groups in dateRegex.findall(text):
      day = str(groups[1])
      slash1 = str(groups[2])
      month = str(groups[3])
      slash2 = str(groups[4])
      year = str(groups[5])
      month_range_30 = [&quot;04&quot;, &quot;06&quot;, &quot;09&quot;, &quot;11&quot;]
      month_range_31 = [&quot;01&quot;, &quot;03&quot;, &quot;05&quot;, &quot;07&quot;, &quot;08&quot;, &quot;10&quot;, &quot;12&quot;]
      month_range_Feb = [&quot;02&quot;]
      #!year_range = np.arange(1000, 3000, 1).tolist()
  
      if len(day) == 1:
          day = &quot;0&quot; + day
      else:
          day = day
      if len(month) == 1:
          month = &quot;0&quot; + month
      else:
          month = month
  
      if month in month_range_31:
          if int(day) &gt; 31:
              day = &quot;Too many days in a month with only 31 days.&quot;
              slash1 = month = slash2 = year = &quot;&quot;
  
      elif month in month_range_30:
          if int(day) &gt; 30:
              day = &quot;Too many days in a month with only 30 days.&quot;
              slash1 = month = slash2 = year = &quot;&quot;
      elif month in month_range_Feb:
          if int(day) &gt; 29:
              day = &quot;Too many days in February.&quot;
              slash1 = month = slash2 = year = &quot;&quot;
      elif int(month) &gt; 12:
          day = &quot;Found an invalid month.&quot;
          slash1 = month = slash2 = year = &quot;&quot;
      elif month in month_range_Feb:
          if (
              int(day) == 29
              and (int(year) % 4 == 0)
              and (int(year) % 400 == 0)
              and (int(year) % 100 == 0)
          ):
              day = day
      elif month in month_range_Feb:
          if (
              int(day) == 29 
              and (int(year) % 4 == 0) 
              and (int(year) % 100 != 0)
          ):
              day = &quot;Found an invalid leap year.&quot;
              slash1 = month = slash2 = year = &quot;&quot;
      #!elif year not in year_range:
      #!day = &quot;Year is out of range.&quot;
      #!slash1 = month = slash2 = year = &quot;&quot;
  
      dates = &quot;&quot;.join([day, slash1, month, slash2, year])
      matches.append(dates)
  
  if len(matches) &gt; 0:
      pyperclip.copy(&quot;\n&quot;.join(matches))
      print(&quot;Copied to clipboard:&quot;)
      print(&quot;\n&quot;.join(matches))
  else:
      print(&quot;No dates found.&quot;)
  
  
  datedetection(text)
  </code></pre>