Mathew O'Rordon seems like a great guy who have written a great regEx to pick up URL's in a text. It works almost flawless. :)
But I found out one problem: If there is a img-tag with a static URL this regEx also catch it, which it should not. I am not fluent on regEx and I do not know what to do with this so it does not catch img src-URL's.
Editor with the script: http://jsbin.com/futuyobawo/edit?html,js,output
Try to paste this into the text and see what happends with the img-code:
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/da/Hermann_Hesse_2.jpg/200px-Hermann_Hesse_2.jpg">
The script:
$(function() {
var urlRegEx = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-]*)?\??(?:[\-\+=&;%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g;
$('#target').html($('#source').html().replace(urlRegEx, "<a href='$1'>$1</a>"));
});
Is there anyone who can see what I need to do to make this regEx exclude img src URL's? That might be the last bit for the ultimate URL-regEx. :)
Hej