JSFiddle - React, Tailwind, and code Playground

JavaScript

var newStr = "my pie is tasty and so is cake".replace(/(pizza|cake|pie|test|horseshoe)/gi, function (match) {
    return match.replace(/./g, '*');
});

alert(newStr);