#include <string>
#include <iostream>
#include <regex>
using namespace std;

int main() {
	std::regex r(R"((\b[[:alpha:]]+\b)|(\b\d+\b))");
	std::string s = "foo bar 123";
	for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), r);
                             i != std::sregex_iterator();
                             ++i)
    {
        std::smatch m = *i;
        std::cout << "Match value: " << m.str() << " at Position " << m.position() << '\n';
        
        for(auto index = 1; index < m.size(); ++index ){
        	if (!m[index].str().empty()) {
				std::cout << "Capture group ID: " << index-1 << std::endl;
				break;
        	}
		}
    }
	return 0;
}
