How to replace the characters !@#$%^*_+\= in a string using RegEx with TypeScript

1 Answer

0 votes
const inputText = "The!quick@brown#fox$jumps%^over*_the+\\lazy=dog.";
const pattern: RegExp = /[!@#$%^*_+=\\]/g;  
const replacement = " ";

// Perform regex replacement
const result: string = inputText.replace(pattern, replacement);

console.log("Original:", inputText);
console.log("Modified:", result);


 
/*
run:
 
"Original:",  "The!quick@brown#fox$jumps%^over*_the+\lazy=dog." 
"Modified:",  "The quick brown fox jumps  over  the  lazy dog." 
 
*/

 



answered Jun 11, 2025 by avibootz
...