Skip to content

Instantly share code, notes, and snippets.

@Beflat
Created June 19, 2012 14:39
Show Gist options
  • Save Beflat/2954564 to your computer and use it in GitHub Desktop.
Save Beflat/2954564 to your computer and use it in GitHub Desktop.
Boost::regex example
//Boost::regex example
//Compile:
//# g++ test.cpp -lboost_regex
#include <iostream>
#include <string>
#include <boost/regex.hpp>
#include <fstream>
using namespace std;
int main(int argc, char** argv) {
boost::regex expression("name=([a-zA-Z0-9]+)");
boost::smatch matched;
ifstream ifs("test.txt");
string line;
while(getline(ifs, line)) {
if(!boost::regex_search(buf, matched, expression, boost::regex_constants::match_partial)) {
continue;
}
cout << "マッチしたパターン全体=" << matched.str(0) << "\t\t";
cout << "キャプチャ部分=" << matched.str(1) << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment