re = /^([2-9]{1})([0-9]{2})([\s.-]?)([2-9]{1})([0-9]{2})([\s.-]?)([0-9]{4})$/m
str = '212-222-1010
(203)753-5678
(203) 753-5678
201-853-6909
800-289-2583
215 5551212
515555121200000
201.853.6909
201 853 6909
201-853-6909
201 853 6909
101.853.6909
1018536909
666-666-6669
(208) 555-1234
666-666-666
666 666 6666
666.666.6666
555 555 5555
222-222-2222
123-123-132
236-548-9888'
# 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