title: Overlapping test in a regex for numbers?
body: <p>I have a challenge here that is beyond my regex scope. If anyone has a suggestion it would be greatly appreciated. I haven't been able to track down anything like this and I'm not sure whether it's doable. I'm using the following expression in java:</p>
  
  <pre><code>"(?i)-?(([1-9]+[0-9]*)|0)(\\.[0-9]*[1-9]+)?(e-?[0-9]+)?"
  </code></pre>
  
  <p>to validate long strings (up to 255 characters) as a confirmation that they at least fit within an allowed numeric value (not necessarily for any type of calculation) and allow the option for scientific notation. The BigDecimal class wasn't doing everything I needed so there are additional checks for leading zeros and trailing zeros in the fractional part because the value must fit with the most simplified representation of the number and follow predictable protocols without any changes. All of the following are returning the results I expect:</p>
  
  <pre><code>String allowance = "(?i)-?(([1-9]+[0-9]*)|0)(\\.[0-9]*[1-9]+)?(e-?[0-9]+)?" ;
  
  System.out.println("0".matches(allowance)) ;   // assert true. Confirm default
  System.out.println("-42".matches(allowance)) ;   // assert true. Confirm integers only
  System.out.println("0.2e543".matches(allowance)) ;   // assert true
  System.out.println("1e543".matches(allowance)) ;   // assert true
  System.out.println("0.2000e543".matches(allowance)) ;   // assert false : trailing zeros after fractional .2
  System.out.println(".2e543".matches(allowance)) ;   // assert false : missing the leading zero
  System.out.println("e543".matches(allowance)) ;   // assert false : malformed
  System.out.println("0001e543".matches(allowance)) ;   // assert false : leading zeros in the integer
  System.out.println("1.0".matches(allowance)) ;   // assert false : easiest match is "1"
  System.out.println("0.0".matches(allowance)) ;   // assert false : easiest match is "0"
  </code></pre>
  
  <p>All of that is fine and good, but I can't figure these two out in the same expression. Maybe one or the other but not both:</p>
  
  <pre><code>System.out.println("-0".matches(allowance)) ;   // Supposed to be FALSE - Should just be "0"
  System.out.println("0e543".matches(allowance)) ;   // Supposed to be FALSE - "0" integer rules out the exponent segment so the easiest match would be "0"
  </code></pre>
  
  <p>Is it possible to trap the segment "-?(([1-9]+[0-9]<em>)|0)(\.[0-9]</em>[1-9]+)?" as two separate but overlapping tests: 1) to rule out "-0" but only if the value doesn't have a fractional value (i.e. -0.5 would be allowable) and then jump forward to 2) rule out the next to follow "e543" exponent if the integer value comes back in the test as "0"?</p>