require ‘test/unit’
class TestFloatRegExp < Test::Unit::TestCase
def test_finds_em
%w{ 1 -2 3.0 0.4 5.0e+5 -6e+06 .7E+7 }.each do |string|
assert( string.match(/[-+0-9eE.]+/), “no match >>#{string}<<” )
end
end
end
Quick caveat - that’s for a c float (as mentioned in that perldoc
snippet). Ruby float (& other numeric) literals allow the underscore
character (with restrictions) as well. So really, it depends on
exactly what you’re parsing and why.
-A
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.