MFCを使う機会が増えそうになってきた。CStringで正規表現する方法を調べたがATL,MFCには(今はもう)無いらしく、C++標準のstd::regexを使うのが一番いいらしい。
// AfxMessageBox #include <afxwin.h> // CString #include <atlstr.h> #include <string> #include <regex> #ifdef _UNICODE using tregex = std::wregex; using tmatch = std::wcmatch; #else using tregex = std::regex; using tmatch = std::cmatch; #endif int main() { CString text = _T("Hello, 123 こんにちは"); #ifdef _UNICODE CString cset= _T(" (UNICODE)"); #else CString cset= _T(" (MULTIBYTE)"); #endif tregex re(_T("こん.*")); tmatch match; if (std::regex_search( LPCTSTR(text), match, re)) { int length = (int)(match[0].second - match[0].first); CString result(match[0].first, length); AfxMessageBox(result + cset); } }