Skip to content

Instantly share code, notes, and snippets.

@nashingofteeth
Created December 6, 2012 08:48
Show Gist options
  • Save nashingofteeth/4222924 to your computer and use it in GitHub Desktop.
Save nashingofteeth/4222924 to your computer and use it in GitHub Desktop.
change plain txt url into html link
<div id="test">
http://google.com
</div>
<script>
var txt = document.querySelector('body').innerHTML;
var pattern = /(HTTP:\/\/|HTTPS:\/\/)([a-zA-Z0-9.\/&?_=!*,\(\)+-]+)/i;
var replace = "<a href=\"$1$2\">$1$2</a>";
var result = txt.replace(pattern , replace);
document.querySelector('body').innerHTML = result;
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment