re = /(http\:|ftp\:|https\:)?(\/\/)?([\w_-]+(?:(?:\.[\w_-]+)+)[\w.,@?^=%&:\/~+#-()].*[\w@?^=%&\/~+#-]?)(?=\s|$)/im
str = 'https://en.wikipedia.org/wiki/Salt_(2010_film)
https://en.wikipedia.org/wiki/Salt_2010_film
https://en.wikipedia.org/wiki/Salt-2010-film
HTTPS://en.wikipedia.org/wiki/Salt-2010-film
//en.wikipedia.org/wiki/Salt_2010_film
https://en.wikipedia.org/wiki/Salt_2010_film?cat=1
https://en.wikipedia.org/wiki/Salt_2010_film#anchor
https://en.wikipedia.org/wiki/Salt_(2010_film)?cat=2
This is a sentence that has a link in it. https://en.wikipedia.org/wiki/Salt_(2010_film)?cat=3 This regex allows me to create an HTML anchor tag around it.'
subst = '<a href="${1}${2}${3}" target="_blank">${1}${2}${3}</a>'
result = str.gsub(re, subst)
# Print the result of the substitution
puts result
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