jQuery Text links to Hyperlinks
This function find all strings containing http and transforms them into real links.
HTML
<div id="links">
<ul>
<h4>Growth Hacking</h4>
http://www.growth-hacker.com
http://growthhackers.com
http://growthbakery.com (FR)
<h4>UX</h4>
http://goodui.org
http://peek.usertesting.com
<h4>Analytics</h4>
http://www.google.com/analytics
http://piwik.org (~ Google Analytics)
</ul>
</div>
JavaScript
// Check the main container is ready
$('#links').ready(function(){
// Get each div
$('ul').each(function(){
// Get the content
var str = $(this).html();
// Set the regex string
var regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/ig
// Replace plain text links by hyperlinks
var replaced_text = str.replace(regex, "<a href='$1'>$1</a>");
// Echo link
$(this).html(replaced_text);
});
});