What would be the regular expression to check whether a string conforms to [-]n[.n], where n is any digit (1-9), with a minimum of 3 digits and maximum of 20? The "-" and/or "." should not be included within the digit count.
So far I have this:
^([-]?(?=.{3,21}$)\d+(?:\.\d+)?)
In large that pattern works, however as soon as you put an illegal character in, it will match everything up to that character. I.e.
-84.427345-388625
will match
-84.427345
however I need it to not match anything at that point. Which is what I can't seem to figure out at the moment.
It should also not match if there are any illegal characters before and/or after the number. The resultant regex needs to be compatible with the standard Java regex libraries.