re = /^(\+?\(61\)|\(\+?61\)|\+?61|\(0[1-9]\)|0[1-9])?( ?-?[0-9]){7,9}$/m
str = '+(61) 455 562 400
+61-455-562-400
+61 455 562 400
+(61)-455-562-400
+(61) 455 562 400
(02) 4371 3164
(02) 4371-3164
02 80268989
03 80268989
04 80268989
05 80268989
433245898
433 245 898
433-245-898
4555-62400
123456
08 54 587 456'
# 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