So I'm trying to make an a sort of auto correct system in my website, and I want to detect a word and if the word is in the image source, then replace it. In my code I am trying to replace the word "Dunk" with SB Dunk. In the source it says Dunk twice, but it only replaces the first time it uses "Dunk", and then keeps making errors and keeps adding more "SB's" to the "Dunk". Heres my code.
//https://stockx-360.imgix.net//Nike-Dunk-Low/Images/Nike-Dunk-Low/Lv2/img01.jpg?auto=format,compress&w=559&q=90&dpr=2&updated_at=1580325806`.replace('%20', '-')
shoesimg.addEventListener('error', function(){
if(shoesimg.src.includes('Dunk')){
const newshoesimg = shoesimg.src.replace(/Dunk/, 'SB Dunk');
shoesimg.src = newshoesimg;
}