How to extract only the digits from a string in JavaScript

1 Answer

0 votes
const str = '45 javascript 9001 c c++ 17';

const digits = str.replace(/[^0-9]/g, "");

console.log(digits); 

  
  
  
  
/*
run:
  
"45900117"
  
*/

 



answered May 4, 2022 by avibootz
...