let str = "I like to eat, eat, eat apples and bananas";
let re = /apples|bananas/gi;
let newStr = str.replace(re, (match) => {
console.log({match});
return match.toUpperCase();
});
console.log(newStr);
Code language: JavaScript (javascript)