This example uses regular expressions (
RegExp) to replace multiple appearances of a substring in a string.
const string = `The car is red. The car is black.`; const replacedString = string.replace(/car|is/g, "·····"); console.log(replacedString); // returns The ····· ····· red. The ····· ····· black.
If you found this useful, you might want to join my newsletter; or take a look at other posts about code, TypeScript, and React.