std::match_results::operator[]
const_reference operator const; | | (since C++11) |
|---|
如果n > 0和n < 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表示目标序列中指定的匹配子范围。
例
二次
#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';
}二次
产出:
二次
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) |
|---|
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

