title: Matching hours/minutes/seconds in regular expressions - a better way?
body: <p>So I need to get hours, minutes and seconds out of entries like these:</p>
  
  <ul>
  <li>04:43:12</li>
  <li>9.43.12</li>
  <li>1:00</li>
  <li>01.04</li>
  <li>59</li>
  <li>09</li>
  </ul>
  
  <p>The first two is hours, minutes and seconds. 
  Next to is minutes and seconds. 
  Last two is just seconds. </p>
  
  <p>And I came up with this regexp, that works..:</p>
  
  <pre><code>\A(?&lt;hours&gt;\d{1,2})(?::|\.)(?&lt;minutes&gt;\d{1,2})(?::|\.)(?&lt;seconds&gt;\d{1,2})\z|\A(?&lt;minutes&gt;\d{1,2})(?::|\.)(?&lt;seconds&gt;\d{1,2})\z|\A(?&lt;seconds&gt;\d{1,2})\z
  </code></pre>
  
  <p>But it is ugly, and I want to refactor it down to not be 3 different expressions (mostly just to learn). I tried this:</p>
  
  <pre><code>\A(?:(?&lt;hours&gt;\d{1,2})(?::|\.){0,1})(?:(?&lt;minutes&gt;\d{1,2})(?::|\.){0,1})(?:(?&lt;seconds&gt;\d{1,2}){0,1})\z
  </code></pre>
  
  <p>But that does not work - minutes and seconds sometimes get screwed up. My brain is hurting, and I can't figure out, what I am doing wrong.</p>