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

int main() {
	std::regex r("(?:^|\n)(\\d+)(?=$|\n)");
    std::string s = "1\n2\n3";
    for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), r);
                             i != std::sregex_iterator();
                             ++i)
    {
        std::smatch m = *i;
        std::cout << "    Capture: " << m[1].str() << " at Position " << m.position(1) << '\n';
    }
	return 0;
}