开发者

Select multiple elements in a regular expression

开发者 https://www.devze.com 2023-03-31 04:19 出处:网络
I\'ve got the URLs in the following style: http://whatever.com/param1/val1/param2/val2 I want to match all key/value pairs. I tried this pattern:

I've got the URLs in the following style:

http://whatever.com/param1/val1/param2/val2

I want to match all key/value pairs. I tried this pattern:

/^http:\/\/whatever.com(?:\/([^\/]+)\/([^\/]+))*$/g

It only matches the last key/value pair.

Unfortunately, I cannot use code to get t开发者_JAVA百科he pairs... How can I capture all pairs?


Try making your match non-greedy by adding a ? after the *:

/^http:\/\/whatever\.com\/(?:([^\/]+)\/([^\/]+)\/?)*?$/g
0

精彩评论

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