tmajor99
asked on
Regular Expression Help
I need a regular expression that will identify decimal values that are less 3 digits in length..
For example:
1.0 --> Yes
2.00 --> Yes
0.01 --> Yes
0.008 --> No
4 --> no
For example:
1.0 --> Yes
2.00 --> Yes
0.01 --> Yes
0.008 --> No
4 --> no
^\d{1,2}\.\d{1,2}$
Jeff, the regex you provided wouldn't allow for 111.0 which according to the question should be a valid match. A correction to mine though:
^[0-9]*\.[0-9]{1,2}$
As 4 should fail but 4.0 shouldn't.
The specs say "less 3 digits in length". so 11.0 or 1.11 would match, but not 111.0 because that is 4 digits. The question doesn't say, but I'm assuming that there won't be a number without a leading or trailing digit on the decimal. so 0.01 for example and not just .01
I'm assuming 4 doesn't match because its not a decimal value.
I'm assuming 4 doesn't match because its not a decimal value.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Jeff, your pattern will match 11.11, which I understand is incorrect.
TechieMD, yours will match 111111.1 and also .1, which I understand is incorrect.
TechieMD, yours will match 111111.1 and also .1, which I understand is incorrect.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window