Boost库中的Regex_replace无法正常工作

我正在尝试删除模式后的子字符串。

我正在尝试使用Boost库,因为它提供了regex_replace,据我所知,应该用给定的新字符串替换每次出现的regex。

std::string s("m_value[0..3]");
boost::regex rgx("\[.*\]");
return boost::regex_replace(s,rgx,"");

此代码返回m_value [03]而不是m_value。有什么想法吗?

ac2234 回答:Boost库中的Regex_replace无法正常工作

您忘了逃脱。

您需要两个反斜杠才能在字符串中添加反斜杠:

boost::regex rgx("\\[.*\\]");

或使用原始字符串文字:

boost::regex rgx(R"(\[.*\])");
本文链接:https://www.f2er.com/3152216.html

大家都在问