title: How to limit the number of digits before/after/ a decimal point and also overall with regex?
body: <p>I'm trying to check that a numeric value has a specific amount of digits.</p>
  
  <ol>
  <li>there shouldn't be more than 19 digits overall</li>
  <li>there shouldn't be more than 17 digits before the decimal point (integer part)</li>
  <li>there shouldn't be more than 4 digits after the decimal point (fractional part)</li>
  <li>there can be a decimal point or not</li>
  <li>there can be a preceding + or - or not</li>
  </ol>
  
  <p>valid examples:</p>
  
  <ul>
  <li>1</li>
  <li>1.0</li>
  <li>.0</li>
  <li>12345678901234567.12</li>
  <li>+12345678901234567.12</li>
  <li>-12345678901234567.12</li>
  <li>123456789012345.1234</li>
  <li>+123456789012345.1234</li>
  <li>-123456789012345.1234</li>
  </ul>
  
  <p>invalid examples</p>
  
  <ul>
  <li>1234567890123456.1234 //because there are 20 digits</li>
  <li>123456789012345678.1 //because there are more than 17 digits before the decimal point</li>
  <li>1.12345 //because there are more than 4 digits after the decimal point</li>
  </ul>
  
  <p>I have tried the examples from <a href="http://www.rexegg.com/regex-lookarounds.html" rel="nofollow noreferrer">this tutorial</a> but can't get them to work how I'd like to. I think I have troubles understanding how to use look aheads/arounds since this part won't really do what I'd like it to:</p>
  
  <pre><code>@Test
  public void testTutorialCode() {
      //min two, max four digits for the whole expression
      Pattern p = Pattern.compile("\\A(?=(?:[^0-9]*[0-9]){2,4})\\z");
      assertFalse(p.matcher("+1234.0").matches());
      assertTrue(p.matcher("12").matches());
      assertTrue(p.matcher("12.12").matches());
      assertTrue(p.matcher("+123.0").matches());
      assertFalse(p.matcher("1234.0").matches());
  }
  </code></pre>