Created
June 19, 2012 14:39
-
-
Save Beflat/2954564 to your computer and use it in GitHub Desktop.
Boost::regex example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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