Guest User

Untitled

a guest
Jun 20th, 2012
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. Google re2 namedcapture, how to parse results in c ?
  2. bool b_matches ;
  3. string s_teststr = " aaaaa flickr bbbb";
  4. RE2 re("(?P<flickr>flickr)|(?P<flixster>flixster)");
  5. assert(re.ok()); // compiled; if not, see re.error();
  6. b_matches = RE2::FullMatch(s_teststr, re);
  7.  
  8. b_matches = RE2::FullMatch(s_teststr, re);
  9.  
  10. // then,
  11. re.NumberOfCapturingGroups() //-> always give me 2
  12.  
  13. re.CapturingGroupNames(); //-> give me a map with id -> name (with 2 elements)
  14.  
  15. re.NamedCapturingGroups() //-> give me a map with name -> id (with 2 elements)
  16.  
  17. string s_teststr = "aaa hello. crazy world bbb";
  18. std::string word[margc];
  19. RE2::Arg margv[margc];
  20. RE2::Arg * margs[margc];
  21. int match;
  22. int i;
  23.  
  24. for (i = 0; i < margc; i++) {
  25. margv[i] = &word[i];
  26. margs[i] = &margv[i];
  27. }
  28. string s_rematch = "((?P<a>hello\.)(.*)(world))|(world)";
  29. match = RE2::PartialMatchN(s_teststr.c_str(), s_rematch.c_str(), margs, margc);
  30. cout << "found res = " << match << endl;
  31. for (int i = 0; i < margc; i++) {
  32. cout << "arg[" << i << "] = " << word[i] << endl;
  33. }
  34.  
  35. string s_rematch = "((?P<a>hello\.d)(.*)(world))|(world)";
  36.  
  37. std::string matchedValue;
  38.  
  39. if (RE2::FullMatch(s_teststr, re, &matchedValue))
  40. {
  41. if (matchedValue.emtpy())
  42. {
  43. //not flickr
  44. }
  45. }
  46. else
  47. {
  48. //matchedValue.empty() == true
  49. }
Advertisement
Add Comment
Please, Sign In to add comment