title: Regex: limit both the whole match AND character classes within
body: <p>Is it possible with regex to allow a match to have a maximum number of characters, divided between different character classes?</p>
  
  <p>I need to match a number of up to 4 digits in total, with or without decimal digits. So these should all match the regex:</p>
  
  <pre><code>123
  1234
  12.34
  123.4
  </code></pre>
  
  <p>But these should not: </p>
  
  <pre><code>12345
  12.345
  </code></pre>
  
  <p>In concept, something like this should work, except it doesn't:</p>
  
  <pre><code>([0-9]{0,4}([.]?[0-9]{0,4})){0,4}
  </code></pre>