title: Python Regular Expression Date YYYY-MM-DD HH:MM:SS
body: <p>Example Data:
  Site,Account,email Address,Date
  01,123456789,test@gmail.com,2017-12-12 10:00:24</p>
  
  <p>I want to use an if statement which will strip out all invalid dates to an exclusion file and write all valid dates to a success file using regular expression.</p>
  
  <pre><code>for row in reader:
                      SITE = row[0].strip()
                      SITE = SITE.rjust(2, '0')
                      ACCOUNT = row[1].strip()
                      ACCOUNT = ACCOUNT.rjust(9, '0')
                      EMAIL = row[2].strip()
                      DATE = row[3].strip()
                      DATA = (SITE, ACCOUNT,EMAIL,DATE)
                      if not re.match("^[0-9]+$", DATE):
                              csvWriter3.writerow(DATA)
                      else:
                              csvWriter.writerow(DATA)
                              csvWriter2.writerow(DATA)
      except IndexError:
          pass
  </code></pre>