std::regex与工作表达式不匹配
std::regex not matching a working expression?
无论出于何种原因,我为程序制作的regexp都不会与任何其他实现中匹配的行匹配。我想知道是否有一些新语法我不懂?
这是我自己的实现:
std::string line, pattern("[LS] 0x[0-9a-fA-F]{8}");
std::regex rx(pattern, std::regex::basic);
uint line_count = 0;
while (getline(in_file, line))
{
line_count++;
if (std::regex_match(line, rx))
{
bool type = (line[0] == 'L');
uint address = (uint) std::stoul(line.substr(4, 8), nullptr, 16);
m_type_store.push_back(type);
m_address_store.push_back(address);
} else {
std::cerr << line << " |" << line_count << '|' << std::endl;
in_file.close();
exit(1);
}
}
每次它都无法匹配文件的第一行,这就是:
S 0x0022f5b4
我觉得这很好…我是不是错过了什么?
在代码中,您使用的是Basic正则表达式。我不确定C++,但通常在Basic RE中,当指定多重性时,需要在{
和}
前面加上。换句话说,您的代码应该是:
std::string line, pattern("[LS] 0x[0-9a-fA-F]{8}");
或者,您可以使用扩展RE,而不是基本RE
相关文章:
- Tbb 库:错误:编写自定义类函数而不是 lambda 表达式时,对函数的调用不匹配
- C++ 正则表达式不匹配空格
- C++正则表达式字符类不匹配
- 调试正则表达式不匹配
- 正则表达式在 c++ 中不匹配?
- 我的 Boost 正则表达式与任何内容都不匹配
- (C++) 确定不匹配的正则表达式捕获组
- 为什么regex_match与我的正则表达式不匹配
- C++:矢量<string>与正则表达式不匹配
- 如何使用正则表达式提取字符串的不匹配部分
- 提升正则表达式不匹配
- 正则表达式与 c++ 不匹配
- 提升正则表达式与空格不匹配"\s"
- Qt 中的不匹配数字正则表达式
- C++11正则表达式不匹配任何内容
- 简单正则表达式不匹配
- Qt正则表达式不匹配
- POSIX正则表达式不匹配
- 提升::正则表达式在长表达式不匹配时抛出错误
- std::regex与工作表达式不匹配