C++ c++;boost regex如何列出所有匹配的元素?

C++ c++;boost regex如何列出所有匹配的元素?,c++,regex,boost,C++,Regex,Boost,我有一个问题,例如,我有一个输入字符串“[1][2][3]”,应该有输出“[1]”“[2]”“[3]”,我尝试了,但效果不好,我的代码如下: //My code const std::string strTypeName = "[1][2][3]"; std::vector<std::string> result; boost::smatch mat; boost::regex reg("(\\[[0-9]*\\])"); if (boost::regex_match(strTy

我有一个问题,例如,我有一个输入字符串“[1][2][3]”,应该有输出“[1]”“[2]”“[3]”,我尝试了,但效果不好,我的代码如下:

//My code 
const std::string strTypeName = "[1][2][3]";
std::vector<std::string> result;
boost::smatch mat;

boost::regex reg("(\\[[0-9]*\\])");
if (boost::regex_match(strTypeName, mat, reg, boost::format_all))
{
    for (boost::smatch::size_type index = 0; index < mat.size(); ++index)
    {
        result.push_back(mat[index]);
    }
}

who can tell me what is the matter with it, It will be great of help !
//我的代码
const std::string strTypeName=“[1][2][3]”;
std::向量结果;
助推:smatch垫;
boost::regex reg(“(\\[[0-9]*\\])”;
if(boost::regex_匹配(strTypeName、mat、reg、boost::format_all))
{
对于(boost::smatch::size_type index=0;index
来自:算法regex\u search和regex\u match使用匹配结果报告匹配的内容;这些算法之间的区别在于,regex_-match将只查找使用所有输入文本的匹配,其中as-regex_-search将在匹配文本中的任意位置搜索匹配,您需要使用
boost::sregex_token_iterator
获取字符串中的所有匹配项。@Wiktor Stribiżew ok非常感谢!它现在工作得很好!