Heads up! This post was written 14 years ago. Some information might be outdated or may have changed since then.
Проста функция която търси www.site.com или http://site.com и го превръща в линкове
String.prototype.parseURL = function() {
    text = this;
    if (!text) {
        return text;
    }
    text = text.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi, function(url) {
        nice = url;
        if (url.match('^https?:\/\/')) {
            nice = nice.replace(/^https?:\/\//i, '');
            return '' + nice + '';
        } else {
            url = nice.replace(/^www./i, '');
            return '' + url + '';
        }
    });
    return text;
}

Пример:
text = text.parseURL();

Back to all posts