我在使用带有 MFC CString 的 Boost 正则表达式时遇到问题。正则表达式非常简单:它必须检查字符串是否以我要查找的 dll 的名称结尾。在下面的代码中,CString 路径确实包含我正在寻找的 dll,但我不知道为什么正则表达式会失败。Uisng 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 );