re = /(\(?(0{1,2}|\+)\d{1,2}\)?)?(([ -]*\d+){8,20})+/m
str = '
https://asd.com/20441235534-aaaaaaaaaaa-
202460676
aasdasd 202460676
https://asd.com/20441235534
202460676-
10 text
1234 text
text 123
00491234567890
+491234567890
0123-4567890
0123 4567 789
0123 456 7890
0123 45 67 789
+490123 4567 789
+490123 456 7890
+49 123 45 67 789
123 4567 789
123 456 7890
123 45 67 789
+49 1234567890
+491234567890
0049 1234567890
0049 1234 567 890
(0049)1234567890
(+49)1234567890
(0049) 1234567890
(+49) 1234567890
text text (0049) 1234567890 text text
text text (+49) 1234567890 text text'
# 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