JS замените целое слово, а не слова в словах
const sampleString = "xsmall small medium";
console.log(sampleString.replace(/\bsmall\b/g, "test"));
Evil Emu
const sampleString = "xsmall small medium";
console.log(sampleString.replace(/\bsmall\b/g, "test"));