Login Latest Snippets Home My Account
Snippee! A personal code snippet manager... Store, share, organize! ...

Convert text urls to links

Published: 2011-08-28 19:01:37 - In: jQuery

$('p').replaceUrl();

$.fn.replaceUrl = function() {
    var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
    this.each(function() {
        $(this).html(
            $(this).html().replace(regexp,'<a href="$1">$1</a>')
        );
    });
    return $(this);
}