嗨,我正在尝试匹配允许查询字符串的特定URL.基本上我需要发生以下事情:
http://some.test.domain.com - 通过http://some.test.domain.com/ - 通过http://some.test.domain.com/home - 通过http://some.test.domain.com/?id=999 - 通过http://some.test.domain.com/home?id=888&rt=000 - 通过http://some.test.domain.com/other - 失败http://some.test.domain.com/another?id=999 - 失败这是我到目前为止:
var pattern = new RegExp('^(https?:\/\/some\.test\.domain\.com(\/{0,1}|\/home{0,1}))$');
if (pattern.test(window.location.href)){
console.log('yes');
}
Run Code Online (Sandbox Code Playgroud)
上面的代码仅适用于前三个而不适用于查询字符串.任何帮助,将不胜感激.谢谢.