How to remove all digits from a string using regex in TypeScript

1 Answer

0 votes
const s: string = "abs322kl59po@$d0057qn8";

// Create a regular expression to match digits
const digitsRegex: RegExp = /[0-9]/g;

// Use String.prototype.replace to replace digit characters with an empty string
const result: string = s.replace(digitsRegex, "");

console.log(result);


   
   
/*
run:
   
"absklpo@$dqn" 
 
*/

 



answered Dec 10, 2024 by avibootz

Related questions

1 answer 121 views
1 answer 128 views
1 answer 129 views
1 answer 122 views
1 answer 140 views
1 answer 118 views
1 answer 127 views
...