... #include <string> #include <regex> ..... { std::string st(....); std::regex exp("@(.*?)"); std::smatch smatch; // same as std::match_results<string::const_iterator> sm; // 遍历匹配 while(std::regex_search(st, smatch, exp)) { // 遍历子分组 for(auto x = smatch.begin(); x != m.end(); x++) std::cout << x->str() << std::endl; // 直接输出某个子分组 std::cout << smatch.format("$1"); } }