re = /^(https?:\/\/)?[A-Za-z0-9\-.]*(:\d+)?\/[A-Za-z0-9\-.]*$/m
str = 'https://GACKOgacko123456789-gacko.domain.COM:80/ABCdef123-.txt
http://GACKOgacko123456789-gacko.domain.COM:80/ABCdef123-.txt
GACKOgacko123456789-gacko.domain.COM:80/ABCdef123-.txt
https://:80/ABCdef123-.txt
http://:80/ABCdef123-.txt
https://GACKOgacko123456789-gacko.domain.COM/ABCdef123-.txt
http://GACKOgacko123456789-gacko.domain.COM/ABCdef123-.txt
GACKOgacko123456789-gacko.domain.COM/ABCdef123-.txt
https:///ABCdef123-.txt
http:///ABCdef123-.txt
https://GACKOgacko123456789-gacko.domain.COM:80/
http://GACKOgacko123456789-gacko.domain.COM:80/
GACKOgacko123456789-gacko.domain.COM:80/
https://:80/
http://:80/
https://GACKOgacko123456789-gacko.domain.COM/
http://GACKOgacko123456789-gacko.domain.COM/
GACKOgacko123456789-gacko.domain.COM/
https:///
http:///
'
# 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