re = /^-?(?!0\d)\d+\.?\d*$/m
str = '0.500
3
0
0.0
30
0.
500000
4000.22
0.50
.3
.44
00
00.5
03.3
00
02
00.0
03
-03
-01
-01.
0004'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html