Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Google re2 namedcapture, how to parse results in c ?
- bool b_matches ;
- string s_teststr = " aaaaa flickr bbbb";
- RE2 re("(?P<flickr>flickr)|(?P<flixster>flixster)");
- assert(re.ok()); // compiled; if not, see re.error();
- b_matches = RE2::FullMatch(s_teststr, re);
- b_matches = RE2::FullMatch(s_teststr, re);
- // then,
- re.NumberOfCapturingGroups() //-> always give me 2
- re.CapturingGroupNames(); //-> give me a map with id -> name (with 2 elements)
- re.NamedCapturingGroups() //-> give me a map with name -> id (with 2 elements)
- string s_teststr = "aaa hello. crazy world bbb";
- std::string word[margc];
- RE2::Arg margv[margc];
- RE2::Arg * margs[margc];
- int match;
- int i;
- for (i = 0; i < margc; i++) {
- margv[i] = &word[i];
- margs[i] = &margv[i];
- }
- string s_rematch = "((?P<a>hello\.)(.*)(world))|(world)";
- match = RE2::PartialMatchN(s_teststr.c_str(), s_rematch.c_str(), margs, margc);
- cout << "found res = " << match << endl;
- for (int i = 0; i < margc; i++) {
- cout << "arg[" << i << "] = " << word[i] << endl;
- }
- string s_rematch = "((?P<a>hello\.d)(.*)(world))|(world)";
- std::string matchedValue;
- if (RE2::FullMatch(s_teststr, re, &matchedValue))
- {
- if (matchedValue.emtpy())
- {
- //not flickr
- }
- }
- else
- {
- //matchedValue.empty() == true
- }
Advertisement
Add Comment
Please, Sign In to add comment