Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
71
rated 0 times [  72] [ 1]  / answers: 1 / hits: 42065  / 14 Years ago, thu, may 20, 2010, 12:00:00

How do I remove numbers from a string using Javascript?



I am not very good with regex at all but I think I can use with replace to achieve the above?



It would actually be great if there was something JQuery offered already to do this?



//Something Like this??

var string = 'All23';
string.replace('REGEX', '');


I appreciate any help on this.


More From » jquery

 Answers
62

d matches any number, so you want to replace them with an empty string:



string.replace(/d+/g, '')


I've used the + modifier here so that it will match all adjacent numbers in one go, and hence require less replacing. The g at the end is a flag which means global and it means that it will replace ALL matches it finds, not just the first one.


[#96724] Tuesday, May 18, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kristineterrak

Total Points: 74
Total Questions: 109
Total Answers: 115

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
;