title: REGEX Date Match Format
body: <p>I currently have a dataset with varying date entries (and a mixture of string entries) for which I need to parse. There are a few: <code>'M/DD/YY'</code>, <code>'M/D/YY'</code>, <code>'MM/DD/YY'</code>, <code>'MM/D/YY'</code>, <code>'MM/DD/YYYY'</code>...). I could use some support with improving my regex to handle the varying formats and possible text entered in the date field.</p>
  
  <p>My current Postgres query breaks out other entries into another column and reformats the date. Although, I've increased the year to 4 digits rather than 2, I believe the issue may live somewhere in the <code>'YYYY-MM-DD'</code> formatting or that my query does not properly accommodate additional formatting within.</p>
  
  <pre><code>CASE WHEN date ~ '^\\\\d{1,2}/\\\\d{1,2}/\\\\d{4}$' THEN TO_DATE(date::date, 'YYYY-MM-DD')
       ELSE NULL END AS x_date,
  
  CASE WHEN NOT date ~ '^\\\\d{1,2}/\\\\d{1,2}/\\\\d{4}$' AND date &lt;&gt; '' THEN date
       ELSE NULL END AS x_date_text
  </code></pre>
  
  <p>For the various date formats, they should be reformatted accordingly and for other non-date values, they should be moved over to the other column.</p>