re = /^([0-9]{8,10}[^a-zA-Z\s])$/mi
str = 'This is a number also 123-456-7890
This is not a number: 123456
This is not a number, but an address 123 456
My parameters are 90/60/90 - 120/150/120 - not a phone number
I am cheeky and I use letter 0 instead of zero 604_213_0293 Or I use | symbol
and also 604_2|3_0293 may happen
The most classical Canadian number is +1(604)123-4567 hi hi
Dashes can be different 123-456–7890
And looks like phone +I(800)-2l4-15O but contain combination with letter
\'oi+I(222)3334444oi\',
\'io+0 (222) 333 444Ooi\',
\'O+l ( 222 ) 3|3 4O40O\',
\'+O+l ( 222 ) 3|3 4O40O\',
069123521
0691235523
06912355312
in text 123-567
+(1)-23567 text
in text 123567-2 text
---------------------------------------
in text 1-800-123-123
1-800-123-123 text
in text 1-800-123-123 text
---------------------------------------
in text 1-800-123-123
1-800-123-123 text
in text 1-800-123-123 text
---------------------------------------
n0OOOOOOOOOOOO
h1iiiiiiiiiiiii
in text +l-800-123-123
1-8oo-I23-i23 text
in text +1 (800)-l23-123 text
phone
\'012345678\',
\'0123456789\',
\'01234567891\',
\'012345678912\',
\'0123456789123\',
\'01234567891234\',
\'012345678912345\',
\'800-1234567\',
\'8Oo-I234567-l\',
\'+1(222)3334444\',
\'+1 (222) 333 4444\',
\'+1 ( 222 ) 333 4444\',
\'+1-222-333-4444\',
\'+1 222 333 4444\',
\'236 - 332 - 6669\',
\'(604)123-4567\',
\'604 123 4567\',
\'604_123_4567\',
\'2368337551\',
\'12223334444\',
\'222) 333 4444\',
\'3333 4444\',
\'(437)1234567\',
\'(888)1234123\',
not a phone
\'0\',
\'01\',
\'012\',
\'0123\',
\'01234\',
\'012345\',
\'0123456\',
\'01234567\',
\'90-60-90\',
\'90/60/90\',
\'0123456789123456\',
\'+X (XXX) XXX XXXX\',
\'1/23-4\',
\'1 / 23 - 4\',
\'1234/12,3-1234\''
# 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