Return to Snippet

Revision: 46986
at May 28, 2011 16:38 by level09


Initial Code
function replaceURLWithHTMLLinks(text) {
  // this looks for urls in html and makes them links
  // I apologize in advance
  var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  return text.replace(exp, "<a href='$1'>$1</a>");
}

Initial URL

                                

Initial Description

                                

Initial Title
Convert links to hyperlinks in JS

Initial Tags
javascript, regexp

Initial Language
JavaScript