re = /(?<!\S)(?:[1-9]\d\d?,\d{3}|(?:[1-9]\d?|1[0-4]\d),\d{3},\d{3}|150,000,000)(?!\S)/m
str = '10,000
10,001
10,100
100,000
999,999
149,999,999
150,000,000
55,555
99,999
73,129
834,101
1,333,333
149,000,000
20,111,000
99,001,000
10,001,000
10,999,999
2,999,999
950,000
999,999
910,000
949,999
950,000
949,999,999
1,999,999,999
100,949,999,999
1
1,0
9,000
9,999
5,555
250,000,000
9,999
100000
150,000,001
150,000,100
150,001,000
150,100,000
151,000,000
9,150,000,000
160,000,000
000,000,000
'
# 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