开发者

Regex to get return the first two ints

开发者 https://www.devze.com 2023-02-28 21:43 出处:网络
Given a string like: #/projects/58/tasks/140 I want to be able to extract 58 & 140. I have the following:

Given a string like: #/projects/58/tasks/140

I want to be able to extract 58 & 140.

I have the following:

parseInt(hash.match(/\d+/开发者_JAVA百科)[0]);

This gets 58, but I can't get 140 with:

parseInt(hash.match(/\d+/)[1])

y? thanks


Use "g" modifier

 hash.match(/\d+/g)
0

精彩评论

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