Hi there, I want to chage all url in my web to clickable automatically. I found a php code to do it: document.writeln(" $text = eregi_replace('([[:space:]()[{}])?(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)([[:space:]()[{}])?', ' <a href=\"2\" target=\"_blank\">2</a> ', $text); "); document.writeln(" $text = eregi_replace('([[:space:]()[{}])?(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)([[:space:]()[{}])?', '1 <a href=\"http://2\" target=\"_blank\">2</a> ', $text); "); document.writeln(" $text = eregi_replace('([[:space:]()[{}])?(file:(/)?[-a-zA-Z0-9@:%_+.~#?&//=]+)([[:space:]()[{}])?', '1 <a href=\"2\">2</a> ', $text); "); document.writeln(" $text = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})', '<a href=\"mailto:1\">2</a>', $text); "); PHP: Can anyone convert it to javascript or give me a javascript to do it? Ex: URL: http://forums.digitalpoint.com Code (markup): To clickable link: http://forums.digitalpoint.com Please help me do this. Thanks very much!
use this regex in javascript /(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/ig
var str = 'http://forums.digitalpoint.com/'; var newstr = str.replace(/(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/ig, function(){ var link = arguments[0]; if(link) { return '<a href="'+link +'">' + link +'</a>'; } } ); Code (markup): sorry, a bit late.