C++正则表达式让所有比赛都在线
C++ Regex getting all match's on line
当逐行读取时,我在每一行上调用此函数以查找函数调用(名称)。 我使用此函数将任何有效字符 a-z 0-9 和 _ 与"("匹配。 我的问题是我不完全了解 c++ 样式正则表达式以及如何让它查看整行以查找可能的匹配项? 这个正则表达式很简单,向前推进只是没有按预期工作,但我学习这是 c++ 规范。
void readCallbacks(const std::string lines)
{
std::string regxString = "[a-z0-9]+(";
regex regx(regxString, std::regex_constants::icase);
smatch result;
if(regex_search(lines.begin(), lines.end(), result, regx, std::regex_constants::match_not_bol))
{
cout << result.str() << "n";
}
}
您需要转义反斜杠或使用原始字符串文字:
std::regex pattern("[a-z0-9]+\(", std::regex_constants::icase);
// ^^
std::regex pattern(R"([a-z0-9]+()", std::regex_constants::icase);
// ###^^^^^^^^^^^##
此外,您的字符范围不包含所需的下划线 ( _
)。
相关文章:
- 使用正则表达式regex_search在字符串中查找字符串
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- C++正则表达式无限循环
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- 定义有趣的宏和正则表达式在Z3 C++绑定
- 带有多个字符分隔符的正则表达式
- C++ 使用增强正则表达式库时断言崩溃
- 有人可以帮助我处理正则表达式吗?
- 使用正则表达式获取大括号块的列表
- 正则表达式以匹配数字的重复模式,后跟任何类型的分隔符?
- 组合正则表达式部分使用 | 不起作用的 C++
- 为什么C++正则表达式这么慢?
- 如何使HTML5电子邮件验证正则表达式在C++中工作?
- 在C++中实现正则表达式
- C++正则表达式替换整个单词
- 用C++编写正则表达式的正确方法是什么?
- 如何从Stroustrup的C++书中解释这个正则表达式?
- 为什么这个正则表达式C++在括号表达式中抛出无效范围异常?
- 为什么在线测试的正则表达式在C++中的表现完全不同
- C++正则表达式让所有比赛都在线