re = /^\d+(?:(?:,\d{3})*(?:\.\d{1,2})?|\.\d+)$/m
str = '1.71
171
1.71717171
171.00
1770
1,700
1,700.00
1,777,777
1,777,777.00
1777777.00
1,444444,4444444,444444.22
1,333,333,333.233
171,00
1777777,00
1,00'
# 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