You can use regex_iterator
to generate all of the matches, then use distance
to count them:
std::regex const expression("[^\s]+");
std::string const text("Harry Botter - The robot who lived.");
std::ptrdiff_t const match_count(std::distance(
std::sregex_iterator(text.begin(), text.end(), expression),
std::sregex_iterator()));
std::cout << match_count << std::endl;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…