MFC CString で Boost 正規表現を使用する際に問題が発生しました。正規表現は非常に単純です。文字列が探している dll の名前で終わっているかどうかを確認する必要があります。以下のコードでは、探している dll が CString パス DOES に含まれていますが、正規表現が失敗する理由がわかりません。ReleaseBuffer を使用するとバッファ サイズが増加するため、パスの長さは MAX_PATH に設定されます。なぜ正しくないか知っていますか?私は多くの試みをしましたが、常に失敗しました。
#include <boost/regex/mfc.hpp>
const CString ValuesDLLName = _T("MyDll.dll");
boost::tregex EndsWithRegex( _T(".+MyDll.dll\s*$") );
//boost::tregex EndsWithRegex1( _T("^.+Values\.dll\\s*$") ); // not working
//boost::tregex EndsWithRegex2( _T("^.+Values\.dll\s*$") ); // not working
//boost::tregex EndsWithRegex3( _T("^.+Values.dll\s*$") ); // not working
//boost::tregex EndsWithRegex4( _T("^.+Values.dll\\s*$") ); // not working
//boost::tregex EndsWithRegex5( _T("^.+Values\.dll\\s*$"),boost::regex::perl ); // not working
//boost::tregex EndsWithRegex6( _T("^.+Values\.dll\s*$"),boost::regex::perl ); // not working
//boost::tregex EndsWithRegex7( _T("^.+Values.dll\s*$"),boost::regex::perl ); // not working
//boost::tregex EndsWithRegex8( _T("^.+Values.dll\\s*$") ,boost::regex::perl); // not working
CString Path;
boost::tmatch What;
_tsearchenv(ValuesDLLName, _T("PATH"), Path.GetBufferSetLength(260));
Path.ReleaseBuffer(260);
bool endsWithDllName = boost::regex_search( Path, What, EndsWithRegex );