[[Programming]] //g++ boostSample.cpp -lboost_regex #include <iostream> #include <string> #include <locale> #include <boost/regex.hpp> using namespace std; int main() { locale::global(locale("ja_JP.UTF-8"));//必須 wcout.imbue(std::locale("ja_JP.UTF-8"));//必須 wcin.imbue(std::locale("ja_JP.UTF-8"));//必須 // VC7(windows) 用には // wcout.imbue(std::locale("japanese")); // wcin.imbue(std::locale("japanese")); // setlocale(LC_CTYPE, "") というして方法もある boost::wregex target(L"(.)れは"); wstring str = L"これはペンです。\ this is a park それは公園です。\ あれは本です。"; // 発見した箇所すべてを表示するための変数 //例えば VC7 では有効 // Linux euc terminalでは表示はされない wstring::const_iterator it = str.begin(), end = str.end(); while(it != end){ boost::wsmatch result; // typedef match_results wsmatch; として定義されている //http://boost.cppll.jp/HEAD/libs/regex/doc/match_results.html if(!boost::regex_search(it, end, result, target)) break; wcout << result.str() << endl; it = result[0].second; } return 0; }