Print the numbers on given array using Regular Expressions.
#Print the three digit numbers in given array
my_array = [111,45456,456,74897,787,45466,789,6587,784,234,456,4658,4587,235,456]
my_reg = []
my_array.each do |k|
my_reg << my_array
end
if my_reg=my_array.select {|n| n.to_s.match(/^\d{3}$/)}
puts my_reg
end
Comments
Post a Comment