Javascript String replaceUrl(target)
String.prototype.replaceUrl = function (target) { var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; if (target) { return this.replace(exp, "<a href='$1' target='" + target + "'>$1</a>"); } else {//from w w w . j a v a2s. c o m return this.replace(exp, "<a href='$1'>$1</a>"); } };