正则表达式验证HTTP地址是否合法

转载:https://blog.csdn.net/fsdad/article/details/52637426

判断url是否合法

const std::regex urlpattern("^(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www.))+(([a-zA-Z0-9._-]+.[a-zA-Z]{2,6})|([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}))(/[a-zA-Z0-9&%_./-~-]*)?$");
if (regex_match(strUrl.c_str(), urlpattern))
{
     //合法url
}
else
{
    //非法url
}
原文地址:https://www.cnblogs.com/chechen/p/10057990.html