re = /^([r])([1-9A-HJ-NP-Za-km-z]{24,34})$/m
str = '// valid addresses
rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn
r9kiSEUEw6iSCNksDVKf9k3AyxjW3r1qPf
rs2qdz5stxyWeMk6sNz5mLY6h5xxPYNJ8u
rfe8yiZUymRPx35BEwGjhfkaLmgNsTytxT
rPE9dw1gR8ravY2o25zudXmj2L28UTNt4D
r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X
// invalid addresses (with O, I, l or 0)
rPE9dw1gR8ravY2o25zudXmj2L20UTNt4D
r9vbV3EHvXWjSkeQ6CAcYVPGel7TuiXY2X
r9vbV3EHvXWjSkeQ6CAcYVPGeqOTuiXY2X
r9vbV3EHvXWjSkeQ6CAcYVPGeqITuiXY2X
'
# 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