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

int main()
{

// Target sequence
std::string s = "function myFunction(p1, p2) { return p1 * p2; }";

// An object of regex for pattern to be searched
regex r("^function\\s+([\\w\\$]+)\\s*\\(");

// flag type for determining the matching behavior
// here it is for matches on 'string' objects
smatch m;

// regex_search() for searching the regex pattern
// 'r' in the string 's'. 'm' is flag for determining
// matching behavior.
regex_search(s, m, r);

// for each loop
for (auto x : m)
    cout << x << " ";
}
