CAtlRegExpの使い方
boost::regexを試そうと思っていたが先にATLのCAtlRegExpを試してみる。
文字列が正規表現にマッチしていなくても
matchContext.m_uNumGroupsは中括弧括りの個数分だけ値を保持するものなのか・・・。
#include "stdafx.h" #include// CAtlRegExp #include int _tmain(int argc, _TCHAR* argv[]) { std::basic_string str = _T("http://d.hatena.ne.jp/twhs/"); std::basic_string strOut; CAtlRegExp<> reg; CAtlREMatchContext<> matchContext; reg.Parse(_T("http://{.*}/{.*}/")); reg.Match(str.c_str(), &matchContext); for (UINT groupIndex = 0; groupIndex < matchContext.m_uNumGroups; ++groupIndex) { const CAtlREMatchContext<>::RECHAR *szStart = 0; const CAtlREMatchContext<>::RECHAR *szEnd = 0; matchContext.GetMatch(groupIndex, &szStart, &szEnd); ptrdiff_t length = szEnd - szStart; strOut = std::basic_string (szStart, length); _tprintf_s(strOut.c_str()); _tprintf_s(_T("\n")); } return 0; }