From: Dan Fitzpatrick Date: 2005-07-14T02:28:26+09:00 Subject: Regex back reference in gsub I am converting URLs in a text file to hyperlinks with the following regex. But the results only show up after the gsub is run a second time. str = "A link to http://ruby-lang.org" str.gsub(/([\s|\>|\[|\(])((ftp:\/\/|http(s?):\/\/))([\w\.\?\/&=\-~:%]+)\b/i, "#{$1}#{$5}#{$6}") #=> "A link to" str.gsub(/([\s|\>|\[|\(])((ftp:\/\/|http(s?):\/\/))([\w\.\?\/&=\-~:%]+)\b/i, "#{$1}#{$5}#{$6}") #=> "A link to ruby-lang.org" Is there another way to do this?