This is my string:
这是我的字符串:
setLocation('http://www.example.com/shop/checkout/cart/add/uenc/aHR0cDovL3d3dy5mYXJtYWNpYWNhbG9pbmkuY29tL3Nob3Av/product/100/form_key/CxWB0lZZuNAENjz5/')
What I need ot do is match /checkout/cart/add
and catch the number /100/
.
This is what I have tried:
我需要做的是匹配/结帐/购物车/添加并捕获数字/ 100 /。这是我尝试过的:
checkout\/cart\/add.+\/(100)\/
and it works, but if I try to extend it to any number:
它工作,但如果我尝试将其扩展到任何数字:
checkout\/cart\/add.+\/([1-9]+)\/
it doesn't work anymore
REGEX101
它不再起作用REGEX101
2 个解决方案
#1
1
change 1
present inside the character class to 0
, so that it would match also the digit 0
.
将字符类中的1更改为0,以便它也匹配数字0。
checkout\/cart\/add.+\/([0-9]+)\/
#2
1
You can also use short hand notation for digits \d
您还可以使用数字的简写符号\ d
checkout\/cart\/add.+\/(\d+)\/
#1
1
change 1
present inside the character class to 0
, so that it would match also the digit 0
.
将字符类中的1更改为0,以便它也匹配数字0。
checkout\/cart\/add.+\/([0-9]+)\/
#2
1
You can also use short hand notation for digits \d
您还可以使用数字的简写符号\ d
checkout\/cart\/add.+\/(\d+)\/