title: How to remove garbage values from dates extracted with regex in Python
body: <p>Goal: extract dates from medical records (stored in pandas Series, dates are in all possible formats) </p>
  
  <p>For numerical dates I used: </p>
  
  <pre><code>str.extractall(r'((?:\b\d{1,2}[/]){1,2}(?:(?:\d{2}\b)|\b\d{4}\b))')
  </code></pre>
  
  <p>Problem: </p>
  
  <p><strong>Input text1</strong>:</p>
  
  <pre><code>"(5/11/85) Crt-1.96, BUN-26; AST/ALT-16/22; Independent
  </code></pre>
  
  <p><strong>Output1</strong>: <code>5/11/85</code> (as wished) but also: <code>16/22</code></p>
  
  <p><strong>Input text2</strong>: </p>
  
  <p><code>[text...] (7/11/77) CBC: 4.9/36/308 Pertinent [...]:</code></p>
  
  <p><strong>Output2</strong>: <code>7/11/77</code> (as wished) but also <code>9/36</code></p>
  
  <p>Especially the second case is hard, because transforming it to date returns: September 2036, so, it can't be selected out that way.</p>
  
  <p><code>[^-]</code> makes it even worse. </p>
  
  <p>The dates are everywhere in the text, like: </p>
  
  <pre><code>[...] has also taken diet pills (last episode in Feb 1993) but [...]
  </code></pre>
  
  <p>Feb 1993 etc. wasn't a problem.</p>