#include <iostream>
#include <string>
#include <memory>
#include <fstream>
#include <iterator>
#include <sstream>
#include <vector>
#include <functional>
#include <regex>
using namespace std;


typedef vector<string> MatchList;
typedef MatchList::iterator MatchListIter;


bool MatchFunc(const boost::smatch &m, MatchList *p)
{
    p->push_back(m.str());
    return true;
}


void RegExTest(const char *pFileName)
{
    ifstream fin(pFileName);
    if (!fin) {
        cout << "file open error !!" << endl;
        return;
    }


    ostringstream oss;
    copy(istreambuf_iterator<char>(fin), istreambuf_iterator<char>(), ostreambuf_iterator<char>(oss));


    tr1::regex expr;
    expr.assign("<[a-zA-Z\\s\\/][^>]*>");    // html 표현식

   
    // replace 매치되는 문자열 치환
    string strResult = boost::regex_replace(oss.str(), expr, "");

    MatchList mlist;


    // grep 매치되는 문자열 찾기
    int nMatch = boost::regex_grep(tr1::bind(MatchFunc, _1, &mlist), oss.str(), expr);

    MatchListIter it = mlist.begin();
   
    for (; it != mlist.end(); ++it) {
        cout << *it << endl;
    }
}

'Dev > C++' 카테고리의 다른 글

export  (0) 2008.05.01
main function  (0) 2008.05.01
boost 를 이용한 TR1 Library 사용하기  (0) 2007.10.10
VC++ 2005 배포  (0) 2007.06.22
Unhandled C++ Exceptions  (0) 2007.06.19

+ Recent posts