您好我正在尝试匹配允许查询字符串的特定 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');
}
上面的代码仅适用于前三个,不适用于查询字符串。任何帮助,将不胜感激。谢谢。