0
我在使用Boost正則表達式和MFC CString時遇到問題。 正則表達式非常簡單:它必須檢查字符串是否以我正在查找的dll的名稱結尾。 在下面的代碼CString路徑包含我正在尋找的DLL,但我不知道爲什麼正則表達式失敗。 Uisng ReleaseBuffer增加了緩衝區大小,所以Path of Path的長度被設置爲MAX_PATH。 你知道爲什麼不正確嗎? 我做了很多嘗試,但總是失敗。增強正則表達式搜索失敗,MFC CString
#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);