re = /^(?!0)(1?[0-9]{0,9}|20[0-9]{8}|21[0-3][0-9]{7}|214[0-6][0-9]{6}|2147[0-3][0-9]{5}|21474[0-7][0-9]{4}|214748[0-2][0-9]{3}|2147483[0-5][0-9]{2}|21474836[0-3][0-9]|214748364[0-7])$/m
str = '1999999999
2055194264
2139898979
2146959544
2147384841
2147479101
2147482900
2147483566
2147483638
2147483639
9999999999
999999999
99999999
9999999
999999
99999
9999
999
99
9
0
01
012
0123
'
# 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