title: Regular expression for matching both HH:MM and HH:MM:SS time format
body: <p>I'd like to write a regular expression for matching both HH:MM:SS and MM:SS.
  <BR><strong>Match</strong></p>
  
  <ul>
  <li>99:43:22</li>
  <li>1:43:22</li>
  <li>01:43:22</li>
  <li>1:43:22</li>
  <li>43:22</li>
  </ul>
  
  <p>so I've tried</p>
  
  <pre><code>(([0-5]?[0-9]):([0-5]?[0-9]))|(([0-9]?[0-9]):([0-5]?[0-9]):([0-5]?[0-9]))
  </code></pre>
  
  <p>What I wanted to add was just a single OR(|) syntax with two time regex.
  <BR>But it doesn't match for HH:MM:SS
  <a href="https://i.stack.imgur.com/tTeiK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tTeiK.png" alt="enter image description here"></a>
  what am I missing?
  I've already looked into those articles:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/7536755/regular-expression-for-matching-hhmm-time-format">Regular expression for matching HH:MM time format</a></li>
  <li><a href="https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s06.html" rel="nofollow noreferrer">https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s06.html</a></li>
  <li><a href="http://regexlib.com/Search.aspx?k=time&amp;AspxAutoDetectCookieSupport=1" rel="nofollow noreferrer">http://regexlib.com/Search.aspx?k=time&amp;AspxAutoDetectCookieSupport=1</a></li>
  </ul>