C++ regex 正则表达式 匹配IP 域名

regex ipPattern("((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])");
regex domainPattern("([0-9A-Za-z\\-_\\.]+)\\.([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)");
string ipStr,domainStr;
ipStr = "192.168.20.250";
domainStr = "www.baidu.com.cn";
if ( regex_match(ipStr,ipPattern ) )
{
cout << _T("合法") << endl;

}
else
{
cout << "您输入的IP地址不合法" < }

if ( regex_match(domainStr,domainPattern ) )
{
cout << _T("合法") << endl;

}
else
{
cout << "您输入的域名地址不合法" < }

你可能感兴趣的:(C++ regex 正则表达式 匹配IP 域名)