#include <iostream>
#include <string>
#include <regex>

int find_year(std::string line, unsigned index = 0)
{
  std::smatch match;
  std::regex expr("\\b([0-9]{4})\\b");

  if ( std::regex_search(line,match,expr) )
    return std::stoi(match[index]);
  else
    throw std::invalid_argument("No number matching a year found!");
}

int main()
{
  int year = find_year("Matthew Alan Aberegg 1963 452,627");
  std::cout << year << "\n";
}
