How to extract all digits from a string in TypeScript

1 Answer

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

const str = '5 type8script 9001 c c++ 17';

const digits: string = extractDigits(str);

console.log(digits);  


/*
run:

58900117

*/

 



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