Skip to content

Instantly share code, notes, and snippets.

@ali-master
Last active December 27, 2016 00:15
Show Gist options
  • Save ali-master/6c979115707d8ef41e8d509d208f3411 to your computer and use it in GitHub Desktop.
Save ali-master/6c979115707d8ef41e8d509d208f3411 to your computer and use it in GitHub Desktop.
Process Text for find and create an anchor link for each of texts link

Process Text for find and create an anchor link for each of texts link

var processText = function (text) {
    var txt = (text || '').replace(/(http(s)?:\/\/[^\s]+)/gi, '<a class="link" href="$1" target="_blank">$1</a>').replace(/\r\n/g, '<br />').replace(/\n/g, '<br />');
    return txt;
};

### Usage
processText(document.body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment