Joho the BlogConvert text with URLs to text with hyperlinks - Joho the Blog

Convert text with URLs to text with hyperlinks

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 to

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“);

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

  1. 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 “”, 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. […] Convert text with URLs to text with hyperlinks […]

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

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

  5. How could I put something like this into my blogger template?

  6. is there a way to make a hyperlink from a url and image?!

    i have lets say 100 urls and 1 image.
    can i apply this image to all the links and make them hyperlinks?!

  7. Natually I will supply you with a net page link within your web weblog. Thanks for sharing.

  8. thanks for this tutorial very helpful i found another reg ex function to sonvert text url to link have a look and with demo

Web Joho only

Comments (RSS).  RSS icon