re = /(?<phone>(380(?:\(|\)|\-|\_|\[|\]|\s+){0,3}((([38]9|4(?:[45][0-5]|87)|5(?:0|6(?:3[14-7]|7)|7[37])|6[36-8]|73|9[1-9])(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d)|((3(?:[1-46-8]2[013-9]|52)|4(?:[1378]2|62[013-9])|5(?:[12457]2|6[24])|6(?:[49]2|[12][29]|5[24])|8[0-8]|90)(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d)|((3(?:5[013-9]|[1-46-8](?:22|[013-9]))|4(?:[137][013-9]|6(?:[013-9]|22)|[45][6-9]|8[4-6])|5(?:[1245][013-9]|6(?:3[02389]|[015689])|3|7[4-6])|6(?:[49][013-9]|5[0135-9]|[12][13-8]))(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3}\d)))|((0(?:\(|\)|\-|\_|\[|\]|\s+){0,3}([38]9|4(?:[45][0-5]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|\s+){0,3}\d(?:\(|\)|\-|\_|\[|\]|\s+){0,3})))/m
str = '066 12 345 67
38 066 123 45 67
38( 066 ) 12 - 34 - 567'
# 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