gpt4 book ai didi

c++ - boost regex_search 找不到第一个匹配项

转载 作者:太空宇宙 更新时间:2023-11-04 12:01:50 26 4
gpt4 key购买 nike

boost::regex re("(abc)(.*?)");
boost::smatch m;
std::string str = "abcdlogin";
boost::regex_search(str, m, re);

我发现 m[1].first 是“abcdlogin”,m[1].second 是“dlogin”。

但是我觉得是m[1].first应该是"abc"吧?

最佳答案

documentation 中所述:

m[n].first: For all integers n < m.size(), the start of the sequence that matched sub-expression n. Alternatively, if sub-expression n did not participate in the match, then last.

m[n].second: For all integers n < m.size(), the end of the sequence that matched sub-expression n. Alternatively, if sub-expression n did not participate in the match, then last.

注意它们是如何迭代器到匹配的子表达式中的。在您的示例中,如果您想要一个带有 "abc" 的字符串,您可以像这样构造一个字符串:std::string s(m[1].first, m[1]。第二);

关于c++ - boost regex_search 找不到第一个匹配项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13794365/

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