Posted By

level09 on 05/28/11


Tagged

javascript regexp hyperlinks


Versions (?)

Convert links to hyperlinks in JS


 / Published in: JavaScript
 

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

Report this snippet  

You need to login to post a comment.