title: date normalization using regular expressions
body: <p>I am doing a date normalization thing where a date not put in a valid format is changed to a valid format. For example</p>
  
  <pre><code>1|1/2002
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>01-01-2002
  </code></pre>
  
  <p>and</p>
  
  <pre><code>5|9-20
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>05-09-0020
  </code></pre>
  
  <p>delimiter is only limited to [- / | ] and any input which doesn't follow has already been thrown out the list. </p>
  
  <p>re.sub(pattern, repl, string, count=0, flags=0)</p>
  
  <p>I looked at the library example but really could not find anything that helps parsing the data.</p>
  
  <pre><code>&gt;&gt;&gt; def dashrepl(matchobj):
  ...     if matchobj.group(0) == '-': return ' '
  ...     else: return '-'
  &gt;&gt;&gt; re.sub('-{1,2}', dashrepl, 'pro----gram-files')
  'pro--gram files'
  &gt;&gt;&gt; re.sub(r'\sAND\s', ' &amp; ', 'Baked Beans And Spam', flags=re.IGNORECASE)
  'Baked Beans &amp; Spam'
  </code></pre>