How to extract all digits from a string in Node.js

1 Answer

0 votes
function extractDigits(str) {
    return str.replace(/[^0-9]/g, "");
}

const str = '824 node3js 9001 c c++ 17';

const digits = extractDigits(str);

console.log(digits);   


/*
run:

8243900117

*/

 



answered May 4, 2022 by avibootz
edited Sep 16 by avibootz
...