String

JavaScript: Basic String Variable

Replace 2 different symbol on the string at the same time

const originalString = "This is a test string with multiple symbols {aaa} and {bbb}";
const newString = originalString
  .replace('{aaa}', "REPLACED_1")
  .replace('{bbb}', "REPLACED_2");

console.log(newString);
// Output: "This is a test string with multiple symbols REPLACED_1 and REPLACED_2"
const originalString = "This is a test string with multiple symbols !@$& and ^%*#";
const newString = originalString
  .replace(/[!@$&]/g, "REPLACED_1")
  .replace(/[\^%*#]/g, "REPLACED_2");

console.log(newString);
// Output: "This is a test string with multiple symbols REPLACED_1REPLACED_1REPLACED_1REPLACED_1 and REPLACED_2REPLACED_2REPLACED_2"