what is the best way to remove non numeric characters from the beginning of a string?
In Javascript, what is the be开发者_C百科st way to remove non numeric characters from the beginning of a string?
-_1234d5fr
should ideally turn into
1234d5fr
str = str.replace(/^\D+/, '');
- regular-expressions.info/Character Classes, Anchors, and Repetition
\D
stands for non-digit characters- The caret
^
matches the position before the first character in the string +
is "one or more of"
How about...
str = str.replace(/^[^0-9]+/, '');
精彩评论