gpt4 book ai didi

c++ - 我如何在 boost::regex 中使用反向引用

转载 作者:行者123 更新时间:2023-11-30 03:06:32 24 4
gpt4 key购买 nike

我想在 boost 版本 1.44 中使用反向引用,但这对我不起作用。这是我的代码:

 boost::regex_constants::syntax_option_type flags = boost::regex::extended;
std::string regx="(aaa)bb\1";
std::cout << "Expression: \"" << regx << "\"\n";
std::string str ="aaabbaaa";
boost::regex e(regx,flags);
if(boost::regex_match(text, what, e))//, boost::match_extra))
{
std::cout<<"found";
} else
{
std::cout<<"not found";
}

这是我的输出:

   Expression:  "(aaa)bbb☺"
** not found **
Press any key to continue . . .

我错过了什么?当我尝试 std::string regx="(aaa)bb\\1" 程序在 boost::regex e(regx,flags); 中崩溃时也许我错过了一些旗帜?

最佳答案

“(aaa)bb\\1”。您需要转义反斜杠。

关于c++ - 我如何在 boost::regex 中使用反向引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6455232/

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