std::match_results<BidirIt,Alloc>:: str
|
string_type str
(
size_type n
=
0
)
const
;
|
(C++11以降) | |
指定された部分マッチを表す文字列を返します。
n == 0 の場合、マッチした式全体を表す文字列が返されます。
0 < n && n < size ( ) の場合、 n 番目 のサブマッチを表す文字列が返されます。
if n >= size ( ) 、マッチしなかった一致を表す文字列が返されます。
この呼び出しは以下と等価です: string_type ( ( * this ) [ n ] ) ;
ready()
は
true
でなければなりません。そうでない場合、動作は未定義です。
目次 |
パラメータ
| n | - | 返すマッチを指定する整数値 |
戻り値
指定されたマッチまたはサブマッチを表す文字列を返します。
例
#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.str(0) << '\n' << "submatch #1: " << sm.str(1) << '\n'; std::regex re2("a(a*)b"); std::regex_search(target, sm, re2); std::cout << "entire match: " << sm.str(0) << '\n' << "submatch #1: " << sm.str(1) << '\n'; }
出力:
entire match: aaab submatch #1: a entire match: aaab submatch #1: aa
関連項目
|
指定された部分マッチを返す
(公開メンバ関数) |