小编Mic*_*ael的帖子

C++ :: Boost :: Regex迭代子匹配

我正在使用带有Boost Regex/Xpressive的命名捕获组.

我想迭代所有子匹配,并获得每个子匹配的值和KEY(即什么["type"]).

sregex pattern = sregex::compile(  "(?P<type>href|src)=\"(?P<url>[^\"]+)\""    );

sregex_iterator cur( web_buffer.begin(), web_buffer.end(), pattern );
sregex_iterator end;

for( ; cur != end; ++cur ){
    smatch const &what = *cur;

    //I know how to access using a string key: what["type"]
    std::cout << what[0] << " [" << what["type"] << "] [" << what["url"] <<"]"<< std::endl;

    /*I know how to iterate, using an integer key, but I would
      like to also get the original KEY into a variable, i.e.
      in case of …
Run Code Online (Sandbox Code Playgroud)

c++ regex boost

6
推荐指数
1
解决办法
2478
查看次数

标签 统计

boost ×1

c++ ×1

regex ×1