Issue
I have image URLs like this
https://cdn.shopify.com/s/files/1/0919/5078/products/DSC_9782-processed_9bef16cb-7700-48d9-ad6d-f9a350e7f6c7.jpg?v=1579953393
I need to insert _small
before the file extension in order to get that image size and it should look like this
https://cdn.shopify.com/s/files/1/0919/5078/products/DSC_9782-processed_9bef16cb-7700-48d9-ad6d-f9a350e7f6c7_small.jpg?v=1579953393
(Images can have different file extensions.)
What's the best way to do this with JavaScript? Maybe Regex?
Tried using this Regex, but it doesn't work with the ?v=1579953393
after the file extension.
Solution
I did manage to rework this answer to do the job. It looks like this and it works as expected.
image = 'https://cdn.shopify.com/s/files/1/0919/5078/products/DSC_9782-processed_9bef16cb-7700-48d9-ad6d-f9a350e7f6c7.jpg?v=1579953393';
image = image.replace(/(\.[\w\d?=_-]+)$/i, '_small$1');
Answered By - Georgi Demirev Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.