Skip to content

Instantly share code, notes, and snippets.

@sebfisch
Created July 24, 2010 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebfisch/488543 to your computer and use it in GitHub Desktop.
Save sebfisch/488543 to your computer and use it in GitHub Desktop.
C++ program that matches a regular expression using Google's re2 library
#include <iostream>
#include <string>
#include <re2/re2.h>
using namespace std;
using namespace re2;
int main(int argc, char* args[]) {
// not syncing C++ and C I/O is faster with simple matchings
ios_base::sync_with_stdio(false);
RE2 re(args[1], RE2::Latin1); // Latin1 is faster than UTF-8
string input; getline(cin, input);
cout << (RE2::PartialMatch(input, re) ? "" : "no ") << "match";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment