re = /^(\+55)?[\s]?\(?(\d{2})?\)?[\s-]?(9?\d{4}[\s-]?\d{4})$/m
str = '+55(16)91555-3456
22 98671 1032
+55 7134764819
(23)99378-4366
+5598683 1021
+551199603-3412
55 98214 9064
(55)98330-7156
(82) 936147156
+552430431084
2140028922
40028922
21 40028922
(21) 4002-8922
+55 21 4002 8922
+55(21)4002-8922
+55986320291'
# 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