主服务:"/xxxxx/yyyyy/200426792?limit=100&offset=0
">
我尝试使用正则表达式:"/xxxxx/yyyyy/\d+/[?]limit[=]100&offset[=]0
">
你能帮忙吗。
您需要转义正斜杠/
,以指示/
是字符串的一部分,而不是正则表达式的一部分。若要转义正斜杠,请在其前面添加一个反斜杠。此外,您的正则表达式当前期望在d+/
指定的数字序列之后出现/
。。。
修复这一切将给你:
/xxxxx/yyyyy/d+[?]limit[=]100&offset[=]0
哪个将成功匹配:
/xxxxx/yyyyy/200426792?limit=100&offset=0
参见以下示例:
const str = "/xxxxx/yyyyy/200426792?limit=100&offset=0";
const regex = //xxxxx/yyyyy/d+[?]limit[=]100&offset[=]0/g;
console.log(regex.test(str)); // true indicates that it matches