logo

Let’s just see what happens

Mobile Version

About me

Newsletter

Videos

Speaker

Hard to Read? Choose a style: Style 1 Style 2 Style 3 Default Toggle Sidebars

Convert text with URLs to text with hyperlinks

Posted on January 16th, 2010

Using a Javascript regex function written by Sam Hesler at StackOverflow (thanks!), I’ve posted a simple little page that lets you turn text that has URLs in it into text that has clickable, hyperlinked URLs. That is, you go from http://www.globalvoicesonline.org to
http://www.globalvoicesonline.org.

The page is: ConvertURLsToLinks.html. It’s quite bareboned, and I’m sure there are lots of sites that do a far better job with many more options. But, it worked well enough for the one job I wanted it for, so maybe it’ll work for you. At least it won’t destroy your original text (although keep the original just in case.)

The regex function I borrowed from Sam Hesler is:

function replaceURLWithHTMLLinks(text) {
var exp = /(b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/ig;
return text.replace(exp,”$1“);
}

Tagged with: javascript • regex

Previous: « Berkman Buzz || Next: Go meta with your Haitian people-finder via Google »

4 Responses to “Convert text with URLs to text with hyperlinks”

  1. Tom Morris, on January 18th, 2010 at 2:22 pm Said:

    There’s an even neater set of regexes hidden inside the source code for Adium, the open-source IM client for OS X. They pick up even fragments of URIs – like if I just wrote “twitter.com”, it’d make it into a link to Twitter.

    Someone – possibly me – should really copy the code out and make it available to a wider community.

  2.  

  3. à regarder sans modération ;o), on January 19th, 2010 at 9:33 am Said:

    [...] Convert text with URLs to text with hyperlinks [...]

  4.  

  5. à regarder sans modération ;o) « remi.astruc, on January 21st, 2010 at 4:03 pm Said:

    [...] Convert text with URLs to text with hyperlinks [...]

  6.  

  7. blueshell, on July 1st, 2010 at 10:36 pm Said:

    Thanks for sharing this regex function to convert text with URLs to text with hyperlinks. It’s useful for me.

  8.  

Leave a Reply


Web Joho only

 

Entries (RSS)
Copy this link as RSS address

Comments (RSS).

Creative Commons License
Joho the Blog by David Weinberger is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. Share it freely, but attribute it to me, and don't use it commercially without my permission.

Joho the blog uses WordPress blogging software.
Thanks, WordPress!