首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::match_results::operator[]

const_reference operator const;

?

(since C++11)

如果n > 0n < size(),返回对std::sub_match表示被捕获的_n_th匹配的目标序列的部分标记子表达式29%。

如果n == 0,返回对std::sub_match表示由整个匹配的正则表达式匹配的目标序列的部分。

如果n >= size(),返回对std::sub_match表示不匹配的子表达式%28-目标序列%29的空子范围。

行为未定义,除非ready() == true...

参数

n

-

integral number specifying which match to return

返回值

引用std::sub_match表示目标序列中指定的匹配子范围。

二次

代码语言:javascript
复制
#include <iostream>
#include <regex>
#include <string>
 
int main()
{
    std::string target("baaaby");
    std::smatch sm;
 
    std::regex re1("a(a)*b");
    std::regex_search(target, sm, re1);
    std::cout << "entire match: " << sm[0] << '\n'
              << "submatch #1: " << sm[1] << '\n';
 
    std::regex re2("a(a*)b");
    std::regex_search(target, sm, re2);
    std::cout << "entire match: " << sm[0] << '\n'
              << "submatch #1: " << sm[1] << '\n';
 
}

二次

产出:

二次

代码语言:javascript
复制
entire match: aaab
submatch #1: a
entire match: aaab
submatch #1: aa

二次

另见

str

returns the sequence of characters for the particular sub-match (public member function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com