^[0-9]\\d*(\\.\\d+)?$
I can’t quite work out what the above regex pattern is looking for. I’m tempted to interpret it as “find anything that is not the numbers 0-9 inclusive, then find zero or more occurrences of a single digit, then find zero or one occurrences of a decimal point followed by at least one digit” but I’m not sure.
Part of my confusion stems from the fact that in the SCJP6 certification book, the not operator is included inside the square brackets, whereas here it’s outside. Also, I am just generally inexperience when it comes to regex.
Can someone please help? [This is from a Java program. Is the above in any way Java specific?] Thanks.
^start of a string[0-9]a single digit\\d*any amount of digits (0-infinity)(\\.\\d+)?Once, or not at all: a dot followed by at least one digit$end of string.You have a complicated regex that will match any floating point or non floiting point number.
Have a look at the
java.util.Patternclass and and the Oracle Java Regex Tutorial.