How to replace characters that don't match regex in Node.js

1 Answer

0 votes
let str = 'NodeJS17$%&';
 
str = str.replace(/[^a-zA-Z]/g, '~');
 
console.log(str); 
   
   
   
   
/*
run:
   
NodeJS~~~~~
   
*/

 



answered Apr 15, 2022 by avibootz
...