std::match_results<BidirIt,Alloc>::operator[]
提供: cppreference.com
< cpp | regex | match results
const_reference operator[]( size_type n ) const; |
(C++11以上) | |
n > 0 かつ n < size() であれば、 n 番目にキャプチャされたマーク付き部分表現にマッチした、ターゲットシーケンスの一部を表す std::sub_match を指す参照を返します。
n == 0 であれば、正規表現全体にマッチした、ターゲットシーケンスの一部を表す std::sub_match を指す参照を返します。
n >= size() であれば、マッチしなかった部分表現 (ターゲットシーケンスの空の部分範囲) を表す std::sub_match を指す参照を返します。
ready() == true でなければ動作は未定義です。
目次 |
[編集] 引数
n | - | 返すマッチを指定する整数 |
[編集] 戻り値
指定されたマッチにマッチしたターゲットシーケンス内の部分範囲を表す std::sub_match を指す参照。
[編集] 例
Run this code
#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
[編集] 関連項目
特定の部分マッチに対する文字シーケンスを返します (パブリックメンバ関数) |