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

1 Answer

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

// Perform regex replacement
const result = str.replace(pattern, replacement);

console.log("Original:", str);
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 by avibootz
...