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 114 views
1 answer 120 views
1 answer 119 views
1 answer 115 views
1 answer 135 views
1 answer 108 views
1 answer 121 views
...