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

int main() {
	std::regex rx_extract("[0-9]+");
	std::regex rx_validate(R"(^\d+(?:,\d+)*$)");
	std::string s = "1,2,3,5";
	if (regex_match(s, rx_validate)) {
		for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), rx_extract);
	                             i != std::sregex_iterator();
	                             ++i)
	    {
	        std::smatch m = *i;
	        std::cout << m.str() << '\n';
	    }
	}
	return 0;
}
