gpt4 book ai didi

C++ boost::regex_match 奇怪的行为

转载 作者:搜寻专家 更新时间:2023-10-31 01:39:48 24 4
gpt4 key购买 nike

尝试 boost::regex_match 并得到一个奇怪的行为。

boost::cmatch what;
std::string fn_re_str = R"(\.sig\|\|([a-zA-Z0-9$]+)\()";
boost::regex fn_re(fn_re_str);
if (boost::regex_match("{var d=a[c];if(d.sig||d.s){var e=d.sig||qt(d.", what, fn_re)) {
std::cout << what[1] << std::endl;
} else {
std::cerr << "not found" << std::endl;
}

qt 应该可以找到。

在这里https://regex101.com/r/iR9rW5/1找到了。

为什么 boost::regex_match 找不到?我错过了什么吗?

最佳答案

regex_match 仅匹配完整输入:documentation

⚠ Important

Note that the result is true only if the expression matches the whole of the input sequence. If you want to search for an expression somewhere within the sequence then use regex_search. If you want to match a prefix of the character string then use regex_search with the flag match_continuous set

使用regex_search

Live On Coliru

#include <boost/regex.hpp>
#include <iostream>

int main() {
boost::cmatch what;
std::string fn_re_str = R"(\.sig\|\|([a-zA-Z0-9$]+)\()";
boost::regex fn_re(fn_re_str);
if (boost::regex_search("{var d=a[c];if(d.sig||d.s){var e=d.sig||qt(d.", what, fn_re)) {
std::cout << what[1] << std::endl;
} else {
std::cerr << "not found" << std::endl;
}
}

打印

qt

关于C++ boost::regex_match 奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30629464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com