I have some string like this:
http://my-site.com/name-274x183.jpg
And I want to cut it down to something like this (Delete -274x183) :
http://my-site.com/name.jpg
How can I do this with javascript or jQuery?
Thanks everyone
I have some string like this:
http://my-site.com/name-274x183.jpg
And I want to cut it down to something like this (Delete -274x183) :
http://my-site.com/name.jpg
How can I do this with javascript or jQuery?
Thanks everyone
You don't need jQuery to do that. Use regular expressions instead:
const url = 'http://my-site.com/name-274x183.jpg'
const result = url.replace(/\/([^/]+)-\d+x\d+\.(\w+)$/, '/$1.$2')
console.log(result)