From: Minero Aoki Date: 2004-02-16T02:28:18+09:00 Subject: Re: hyperlinking URLs (and emails?) in text Hi, In mail "hyperlinking URLs (and emails?) in text" Ruby Baby wrote: > Anyone got a better version, or care to improve on this one? > > Just trying to hyperlink URLs in text (and in future, email addresses, without needing mailto:). If you have ruby 1.8.1: require 'uri' text.gsub(URI.regexp(%w(http https ftp))) {|urlstr| %Q[#{urlstr}] } Also, you will want to escape '<' '>' '&' in text: require 'uri' require 'cgi' text.gsub(/[<&>"']|#{URI.regexp(%w(http https ftp))}/) {|matched| case matched when /[<&>"']/ CGI.escapeHTML(matched) else url = CGI.escapeHTML(matched) %Q[#{url}] end } Regards, Minero Aoki