/*
* 输入是789.123.456, 输出的是789
*/
void get()
{
std::regex ip_reg("(.*)\.123\.456");
std::smatch matchResult;
string inputStr;
std::getline(std::cin,inputStr);
//正则匹配
if (std::regex_match(inputStr,matchResult,ip_reg))
{
cout << "Match: ";
//打印子表达式结果
for (size_t i = 1; i < matchResult.size(); ++i)
{
cout << matchResult[i] << " ";
}
}
else
{
cout << "Not Match!";
}
}
C++正则表达式提取匹配到的字符串
最新推荐文章于 2024-02-28 22:03:33 发布