从tr1::regex_search中获取匹配索引

Get index of match from tr1::regex_search

本文关键字:获取 索引 search tr1 regex      更新时间:2023-10-16

使用std::tr1::regex_search时如何获得匹配的索引?

// sequence of string sub-matches
std::tr1::smatch result;
if (!std::tr1::regex_search(text, result, pattern))
    return false;

我只能从std::tr1::smatch result变量中获得字符串,但不能获得匹配的索引。

我错过了它,因为我搜索了一个index方法,但它就在那里作为一个方法- std::tr1::smatch::position()将给出匹配的索引。