I have the following image src:
<img src="http://xyz.example.com/abc/def/ghi/someimagename.jpg">
How can I use jquery to extract the image name without the extension e.g. in the above case this would be someimagename
?
I have the following image src:
<img src="http://xyz.example.com/abc/def/ghi/someimagename.jpg">
How can I use jquery to extract the image name without the extension e.g. in the above case this would be someimagename
?
You can use regex /\/([^\/]+?)\.jpg">/
and get the capturing group value
var str = '<img src="http://xyz.example.com/abc/def/ghi/someimagename.jpg">';
var res = str.match(/\/([^\/]+)\.jpg">/)[1];
document.write(res);
you can do this too.
var string = '<img src="http://xyz.example.com/abc/def/ghi/someimagename.jpg">';
string = string.split("ghi/")[1].split(".")[0];
EDIT:
or you can do the following, which will work pretty good for any kind of url
var string = '<img src="http://xyz.example.com/abc/def/ghi/someimagename.jpg">';
function reverse(s){
return s.split("").reverse().join("");
}
string = reverse(string).split(".")[1].split("/")[0];
string = reverse(string);