I want to replace the four last characters of an image.
Q1)
I want this:
http://domain.com/image1.jpg
http://domain.com/image2.png
http://domain.com/image3.gif
to become:
http://domain.com/image1-big.jpg
http://domain.com/image2-big.png
http://domain.com/image3-big.gif
Q2)
And then I want to be able to do the opposite way (removing -big from the file name)
Any suggestions for Q1 and Q2?
var str = 'http://domain.com/image1.jpg';
// Embiggen
str.replace(/\.(gif|png|jpg)$/, '-big.$1');
// Unbiggen
str.replace(/-big\.(gif|png|jpg)$/, '.$1');
It's a bit naive, but it should work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.