I want to find string from given text. My regular expression is not working. i am not sure what i did mistake. Can some one help me please.
I am expecting ouput as : myFunction
#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 << " ";
}