Subject: | more complete regexp for numbers |
Here are some better regular expressions for matching numbers:
validate_int:
your regexp is OK because YAML doesn't seem to allow exponents for
integers (or at least the ruby module doesn't allow it)
validate_float:
if ($data !~ m{^[+-]?\d+\.\d*([eE][-+]?\d+)?$}) {
validate_number:
if ($data !~ m{^[+-]?\d+(\.\d*)?([eE][-+]?\d+)?$}) {
Note that the expression for validate_number will match "1e+10" which
neither validate_int nor validate_float will match. I thought this may
be a good way to do it since "1e+10" isn't a valid YAML number, so there
is no way to know whether it should be int or float. This type of value
is however output by the perl YAML writers so should be allowed by the
validator in the same way that 0 and 1 are allowed for boolean even
though they are not really YAML boolean values.