目前,我正在使用以下正则表达式来匹配网址
/(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,63}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?/
我想知道如何修改它,使其仅与域名匹配而不包含子文件夹。
例如
http://thisiatest.com/ -> Good
thisisatest.com -> Good
http://thisiatest.com -> Good
http://thisisatest.com/folder/ -> Bad
thisisatest.com/folder/ -> Bad
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句