I am trying to remove part of the name of the image to create thumbnails.
The image name is created dynamically ie HG57JWY_0.jpg, HG57JWY_1.jpg, HG57JWY_2.jpg. I managed to remove the .jpg using:
var imageName = $('#slider1 li img').prop('src').match(/(\w*)\.\w{3,4}$/)[1];
My problem is that i cant figure how to remove the "_0"
return '<img src="sample-img/'+ imageName +'_' + [i -+ 1] + '.jpg">';
this generates HG57JWY_0_0.jpg
Any ideas how i do that?
Edit: Forgot to mention that big image and the thumb are in different folder. So i display the big image in one place holder with the src = http://mydomain.com/sample-img/imagename.jpg
and i place the thumbs in a list with the src = http://mydomain.com/sample-img-thumb/imagename.jpg
Edit 2:
Thanks to Alexander, i used my original code
var imageName = $('#slider1 li img').prop('src').match(/(\w*)\.\w{3,4}$/)[1];
and added his .split("_")[0]
var imageName = $('#slider1 li img').prop('src').match(/(\w*)\.\w{3,4}$/)[1].split("_")[0];
This takes the whole image src ie http://mydomain/imageFolder/image_1.jpg
, and returns just the "image".
Then i was able to use what ever path i want with
return '<img src="sample-img/'+ imageName +'_' + [i -+ 1] + '.jpg">';
and just changed the sample-img/ with what i needed.