All I want is to strip all the numbers from a string.
So
var foo = "bar01";
alert(foo.replace(/\d/,''));
Which obviously gives “bar1” because I’ve only specified one digit. So why doesn’t this work:
var foo = "bar01";
alert(foo.replace(/\d*/,''));
Which gives “bar01”
You must add the
globaloptionClearly you can even do something like
but I don’t know if it will be faster (and in the end the difference of speed would be very very very small unless you are parsing megabytes of text)
If you want to test http://jsperf.com/replace-digits the second one seems to be faster for “blobs” of 10 digits and big texts.