#include #include #include int main() { std::string expr = "", s = ""; std::smatch matches; if (std::regex_match(s, matches, std::regex(expr))) { // matches[0] contains the original string. // matches[n] contains a sub_match object for each matching subexpression for (auto i = 0; i < matches.size(); ++i) { // sub_match is pair of iterators to the first // and one past the last chars of the matching subexpression // (matches[i].first, matches[i].second); std::string match = matches[i]; std::cout << "\tmatches[" << i << "] = " << match << '\n'; } } else std::cout << "The regexp \"" << expr << "\" does not match \"" << s << "\"\n"; }