我想在C++中取一个字符串,并找到其中包含的项目名称和路径。该字符串的格式为:与VS2010的正则表达式C++/Boost
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenGL01", "OpenGL01\OpenGL01.vcxproj", "{65E58BFD-4339-44BA-BA9B-B2B8A5AC1FE1}"
而正则表达式是:
boost::regex expression("(Project\(\"\{.*\}\"\)) ?= ?(\".*\"), ?(\".*\"), ?(\"\{.*\}\")");
,但此行产生异常错误:
Unhandled exception at 0x7512d36f in kmCompile2010.exe: Microsoft C++ exception:
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::regex_error> >
at memory location 0x004ce13c..
这是完整的功能:
BOOL CSlnFile::ReadProjectsSolution()
{
CString sLine;
boost::regex expression("(Project\(\"\{.*\}\"\)) ?= ?(\".*\"), ?(\".*\"), ?(\"\{.*\}\")");
BOOL bCheck = FALSE;
SeekToBegin();
while(ReadString(sLine) && !bCheck) {
// CString to char*
CT2A temp(sLine); // uses LPCTSTR conversion operator for CString and CT2A constructor
const char* pszA = temp; // uses LPSTR conversion operator for CT2A
std::string strA(pszA); // uses std::string constructor
boost::smatch what;
if (regex_match(strA, what, expression, boost::match_extra)) {
// TODO
}
}
return bCheck;
}
我不是和我的错误。你可以帮我吗?
你需要双精度除了引号之外的所有内容都可以转义:'boost :: regex expression(“(Project \\(\”\\ {。* \\} \“\\))?=?(\”。* \“),? “。* \”),?(\“\\ {。* \\}}”)“);' – ildjarn 2012-04-23 21:20:26