in reply to vallidating a regular expression
Matching one of two patterns eases the problem:
use strict; use warnings; while (<DATA>) { if (/^(10|\d)$/) { print "Match for $_"; } else { print "Rejected $_"; } } __DATA__ 0 1 9 10 11 20 99 100
Prints:
Match for 0 Match for 1 Match for 9 Match for 10 Rejected 11 Rejected 20 Rejected 99 Rejected 100
Update: substituting /^0*(10(\.0+)?|\d(\.\d+)?)$/ for the regex allows leading zeros and decimal fractions. With the test data:
0.1 01 1 1.0 1.01 9.9 10 10.0 10.01 11 20 99 100
the code prints:
Match for 0.1 Match for 01 Match for 1 Match for 1.0 Match for 1.01 Match for 9.9 Match for 10 Match for 10.0 Rejected 10.01 Rejected 11 Rejected 20 Rejected 99 Rejected 100
|
|---|