title: Why does this regex (see inside) match 24+? (and how to matches the exact pattern)
body: <p>This is the regex:</p>
  
  <blockquote>
    <p>[0-9]|([0-1][0-9])|2[0-3]</p>
  </blockquote>
  
  <p>Aim: match numbers: 0 to 23</p>
  
  <p>(working version: </p>
  
  <blockquote>
    <p>([0-1][0-9]?)|2[0-3]</p>
  </blockquote>
  
  <p>)</p>
  
  <p>The issue with the <strong>first</strong> version ([0-9]|([0-1][0-9])|2[0-3]):</p>
  
  <p>To me this means: match these numbers (or a string/number containing them)</p>
  
  <ul>
  <li>0,....,9</li>
  <li>01, ...., 09</li>
  <li>10, ..., 19</li>
  <li>20, ..., 23</li>
  </ul>
  
  <p>but it matches also <strong>24</strong> for example. Why?</p>
  
  <p>I also tried (to match the <strong>exact</strong> pattern and not a potential superset):</p>
  
  <ul>
  <li><p>to use <strong>\b</strong> at beginning and end of pattern. Result: <strong>matches 0 until 10 only</strong></p></li>
  <li><p>to use ^ (beginning) + $ (end) but 20, 21, ... are <strong>not matched</strong></p></li>
  </ul>
  
  <p><strong>Tried in <a href="http://regexr.com/" rel="nofollow">http://regexr.com/</a></strong></p>