Is it possible to partially replace the url of the image img ? It is necessary that the url is changed to the given one and only up to definitely words, in this case it is newwiki .
This code finds images and changes the url, replacing /newwiki/ with http://drug/newwiki . At the same time, the initial path obviously does not change and the url remains incorrect.
var img = $('img').first(); $.each(img.get(0).attributes, function() { console.log(img); if (this.name != 'data-base-url') { img.attr(this.name, img.attr(this.name).replace(/newwiki/, 'http://drug/newwiki')); } }); The main difficulty is that the first part of the url can be different, and not known in advance.
How can I change the url in this case?
UPD
An example of a valid and incorrect url:
Invalid url http://crm.mv.portal-new.web-dev.ru/newwiki/s/ru_RU/6217/82a642d727bee456b0a91262638763d5620b1a86.8/_/images/icons/emoticons/smile.png
right url http://drug/newwiki/s/ru_RU/6217/82a642d727bee456b0a91262638763d5620b1a86.8/_/images/icons/emoticons/smile.png