How to remove punctuation from a string in TypeScript

1 Answer

0 votes
let str: string = "TypeScript: is a free, ~!@#$%^&*() open-source high-level programm[i]ng language.";
         
str = str.replace(/[^\w\s]|_/g, "").replace(/\s+/g, " ");
         
console.log(str);
 

 
/*
run:
     
"TypeScript is a free opensource highlevel programming language" 
     
*/

 



answered Jul 31, 2024 by avibootz
...