The following regex matches URL's pretty damn well, but won't match URLs that DON'T end with a forward slash (/).
/^(http|https)\:\/\/[\w\d\-_]+(\.[\w\d\-_]+)+([\w\-\.,@?^=%&\:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/
This actually might not be the problem, it could be something with the following code as well:
var url_arr = unsafe.match(url_regex); //test if its a url
if (url_arr) {
if (url_arr[url_arr.length-1].match(/(.png|.gif|.jpeg|.jpg)/)) {
//do some stuff
}
}
it seems to be the url_arr[url_arr.length-1] that is undefined.