fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4. #include <iterator>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10. // Target sequence
  11. std::string s = "function myFunction(p1, p2) { return p1 * p2; }";
  12.  
  13. // An object of regex for pattern to be searched
  14. regex r("^function\\s+([\\w\\$]+)\\s*\\(");
  15.  
  16. // flag type for determining the matching behavior
  17. // here it is for matches on 'string' objects
  18. smatch m;
  19.  
  20. // regex_search() for searching the regex pattern
  21. // 'r' in the string 's'. 'm' is flag for determining
  22. // matching behavior.
  23. regex_search(s, m, r);
  24.  
  25. // for each loop
  26. for (auto x : m)
  27. cout << x << " ";
  28. }
  29.  
Success #stdin #stdout 0s 15336KB
stdin
Standard input is empty
stdout
function myFunction( myFunction