re = /^(?:(?=(?:\s*\d\s*){10}$)(?:0\s*[2378]|1[38])|(?=(?:\s*\d\s*){6}$)1\s*3).*/m
str = '0299998888
02 99998888
02 9999 8888
02 99 998 888
0299 998 888
0299 998888
131999
131 999
13 19 99
1300123456
1300 123456
1300 123 456
1300 12 34 56
1300 12 34 56
13145
1300-123-456
9999 8888
(02) 9999 8888'
# 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