I'm currently using the following code, to search the a div on a page for URLs and replace them with a tags.
However when we have a embed tags within the div it messes up the links within these tags.
function replaceURLWithHTMLLinks(text) {
return text.replace(/(ftp|http|https|file):\/\/[\S]+(\b|$)/gim,'<a href="$&" class="my_link" target="_blank">$&</a>').replace(/([^\/])(www[^ <]+(\b|$))/gim,'$1<a href="http://$2" class="my_link" target="_blank">$2</a>');
}
$(document).ready(function(){
var htmlStr = $("div.content-a").html();
var htmlStrAfter = replaceURLWithHTMLLinks(htmlStr);
$("div.content-a").html(htmlStrAfter);
});
Can anyone tell be how to perhaps exclude any http://... that are preceded by a " or ' ?
Or similar?