【问题标题】:Get index of match from tr1::regex_search从 tr1::regex_search 获取匹配索引
【发布时间】:2013-03-18 16:37:41
【问题描述】:

使用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 变量中获取字符串,但不能获取匹配的索引。

【问题讨论】:

    标签: c++ regex tr1


    【解决方案1】:

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

    【讨论】:

    • 嗯,这根本没有升级。
    • 感谢这个答案 - stackoverflow.com/a/234277/492336,我找到了方法。这是关于 Boost 的,但 tr1 中的正则表达式类似乎是相同的。所以 StackOverflow 还是帮了大忙。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-10
    • 2018-10-26
    相关资源
    最近更新 更多