How to extract only the digits from a string in TypeScript

1 Answer

0 votes
const str = '5 typescript 9001 c c++ 17';
 
const digits = str.replace(/[^0-9]/g, "");
 
console.log(digits); 
 
   
   
   
   
/*
run:
   
"5900117" 
   
*/

 



answered May 4, 2022 by avibootz
...