#include
#include
#include
using namespace std;
int main()
{
std::string str1 ("www.youku.com");
std::string str2 ("www.you.ku.com");
std::string str3 ("www.youku.com.com");
std::regex rx("(.*)youku.com(.*)");
bool bl1 = std::regex_match(str1.begin(),str1.end(), rx);
bool bl2 = std::regex_match(str2.begin(),str2.end(), rx);
bool bl3 = std::regex_match(str3.begin(),str3.end(), rx);
if (bl1)
std::cout << "OH YES" << std::endl;
else
std::cout << "OH NO" << std::endl;
if (bl2)
std::cout << "OH YES" << std::endl;
else
std::cout << "OH NO" << std::endl;
if (bl3)
std::cout << "OH YES" << std::endl;
else
std::cout << "OH NO" << std::endl;
return 0;
}
要支持c++11的环境
使用正则表达式
\byouku\.com\b.*\b
请搜索正则表达式的用法