10000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
例如:
http://www.qq.com // 通过 http://www.qq.com.cn // 不通过 http://www.qq.com/a/b // 通过 http://www.qq.com?a=1 // 通过 http://www.123qq.com?a=1 // 不通过
解答:正则
function check(url){ if(/\/\/w+\.qq\.com[^.]*$/.test(url)){ return true; }else{ return false; } } check('http://www.qq.com') // true check('http://www.qq.com.cn') // false check('http://www.qq.com/a/b') // true check('http://www.qq.com?a=1') // true check('http://www.123qq.com?a=1') // false
这个正则很简单,包含 .qq.com 就可以,但是有一种情况,如果域名不是包含 qq.com 而仅仅是参数后面包含了 qq.com 怎么办?例如 http://www.baidu.com?redirect=http://www.qq.com/a
.qq.com
qq.com
http://www.baidu.com?redirect=http://www.qq.com/a
check('http://www.baidu.com?redirect=http://www.qq.com/a') // true
如何排除这种情况?
function check(url){ if(/^https?:\/\/w+\.qq\.com[^.]*$/.test(url)){ return true; }else{ return false; } } check('http://www.qq.com') // true check('http://www.qq.com.cn') // false check('http://www.qq.com/a/b') // true check('http://www.qq.com?a=1') // true check('http://www.123qq.com?a=1') // false check('http://www.baidu.com?redirect=http://www.qq.com/a') // true
若有收获,就点个赞吧
The text was updated successfully, but these errors were encountered:
最后一个结果是false啊~
Sorry, something went wrong.
function check (url) { let reg = /^https?://\w+.qq.com[^.]*$/ return reg.test(url) }
No branches or pull requests
例如:
解答:正则
这个正则很简单,包含
.qq.com
就可以,但是有一种情况,如果域名不是包含qq.com
而仅仅是参数后面包含了qq.com
怎么办?例如http://www.baidu.com?redirect=http://www.qq.com/a
如何排除这种情况?
若有收获,就点个赞吧
The text was updated successfully, but these errors were encountered: