开发者

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]+/, '');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜