我正在尝试匹配 Javascript 中的几种 URL 模式中的任何一种。图案是:
主页 -/之后没有任何东西。
三个解决方案页面之一。每个solutions(number)后面都可以跟 a/和任何字符。
/solutions/99043 或者 /solutions/99043/blah
/solutions/60009 或者 /solutions/60009/blah
/solutions/40117 或者 /solutions/40117/blah
搜索:/search后跟任何字符,例如?blah.
我试过的正则表达式如下:
/\/$|\/solutions\/(99043|60009|40117)\/.*|\/search.*/
在这个函数中:
(function () {
const urlPath = window.location.pathname;
if (urlPath.match(/\/$|\/solutions\/(99043|60009|40117)\/.*|\/search.*/)) {
console.log("urlPath", urlPath);
}
})()
它不起作用,因为一切似乎都匹配。任何人都知道我哪里出错了?
基于评论,匹配但不应该的 URL 示例: /solutions/
MMTTMM
守着一只汪
慕勒3428872
喵喔喔
随时随地看视频慕课网APP
相关分类