$ sudo apt-get install libpcre3-dev
程式碼:
#include <iostream>
#include <string>
#include <pcrecpp.h>
int main() {
std::string s = "Hello 123-234-456 World";
pcrecpp::RE("[0-9]+").GlobalReplace("", &s);
std::cout << "Result: " << s <<"\n";
return 0;
}
結果:
$ g++ -g t.cpp -lpcrecpp && ./a.out
Result: Hello -- World
I recommend RE2, written by author of Go lang.
回覆刪除Official repo: https://code.google.com/p/re2/ .
And, "If you absolutely need backreferences and generalized assertions, then RE2 is not for you, but you might be interested in irregexp, Google Chrome's regular expression engine", quote from above link.