使用 VS2010 C++/增强的正则表达式
Regular Expression with VS2010 C++ / Boost
我正在尝试在C++中获取一个字符串并找到其中包含的项目名称和路径。该字符串的格式为:
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenGL01", "OpenGL01OpenGL01.vcxproj", "{65E58BFD-4339-44BA-BA9B-B2B8A5AC1FE1}"
正则表达式为:
boost::regex expression("(Project("{.*}")) ?= ?(".*"), ?(".*"), ?("{.*}")");
但是此行会生成异常错误:
在 kmCompile2010.exe 中0x7512d36f处未处理的异常:Microsoft C++异常:内存位置 0x004ce13c 处
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::regex_error> >
。
这是完整的功能:
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 中尝试以下正则表达式,它在 perl 中工作:
{([^}]+)}"[^"]*"([^"]+)", "([^"]+)", "{([^}]+)
我在命令行上尝试过:
echo 'Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenGL01", "OpenGL01OpenGL01.vcxproj", "{65E58BFD-4339-44BA-BA9B-B2B8A5AC1FE1}"' | perl -ne 'my ($a, $b, $c, $d) = /{([^}]+)}"[^"]*"([^"]+)", "([^"]+)", "{([^}]+)/; print "$a, $b, $c, $d"'
相关文章:
- 带有多个字符分隔符的正则表达式
- 查找中间两个数字的正则表达式的匹配项
- 如何编写将验证以下字符串的正则表达式?
- C++带有捕获组的正则表达式字符串文本
- 使用C++的正则表达式
- 需要忽略日期/序列号,但匹配字符串其余部分的正则表达式
- 需要支持定义正确的正则表达式
- python中的正则表达式删除了太多
- C++中的正则表达式存在问题
- 在带有brew的MacOS上链接时缺少增强ICU正则表达式符号
- 以下格式的正则表达式
- C++ 中用于搜索字符串模式的正则表达式
- C++无符号字符串类型的正则表达式
- (C++) 确定不匹配的正则表达式捕获组
- C++抛出错误"Invalid special open parenthesis."中的正则表达式
- GCC 和 LLVM 中的正则表达式速度相差 1000 倍
- 不同换行符的正则表达式
- 使用具有特殊字符的正则表达式标记 C++ 字符串
- 使用 VS2010 C++/增强的正则表达式
- 增强特殊字符的正则表达式模式