Skip to content

Instantly share code, notes, and snippets.

@chezou
Created November 25, 2011 15:42
Show Gist options
  • Save chezou/1393827 to your computer and use it in GitHub Desktop.
Save chezou/1393827 to your computer and use it in GitHub Desktop.
Sample cord of re2 of PartialMatchN
#include <iostream>
#include <string>
#include <re2/re2.h>
#include <vector>
using namespace std;
int main(){
string str("あぶらかたぶら");
re::RE2 re("(.ぶ)");
re2::StringPiece input(str);
int groupSize = re.NumberOfCapturingGroups();
vector<re2::RE2::Arg> argv(groupSize);
vector<re2::RE2::Arg*> args(groupSize);
vector<re2::StringPiece> ws(groupSize);
for (int i = 0; i < groupSize; ++i) {
args[i] = &argv[i];
argv[i] = &ws[i];
}
re2::RE2::PartialMatchN(input, re, &(args[0]), groupSize);
cout << groupSize << endl;
for (int i = 0; i < groupSize; ++i)
cout << ws[i] << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment