Ⅱ. 1回マッチさせたい場合
サンプルプログラム
Source.cpp
// #include <regex> std::wstring str(L"key01=value02&key02=value02"); std::wregex pattern(LR"((key[0-9]{1,})=([a-z0-9]{1,}))"); std::wsmatch results; std::regex_search(str, results, pattern); std::wcout << results[1].str() << std::endl; std::wcout << results[2].str() << std::endl;
実行結果
key01 value02
Ⅲ. 複数マッチさせたい場合
サンプルプログラム
Source.cpp
// #include <regex> std::wstring str(L"key01=value02&key02=value02"); std::wregex pattern(LR"((key[0-9]{1,})=([a-z0-9]{1,}))"); std::wsregex_iterator it(str.begin(), str.end(), pattern); std::wsregex_iterator end; while (it != end) { std::wcout << "key:" << (*it)[1].str() << std::endl; std::wcout << "value:" << (*it)[2].str() << std::endl; it++; }
実行結果
key:key01 value:value02 key:key02 value:value02