std::match_results<BidirIt,Alloc>::str
From cppreference.com
< cpp | regex | match results
| string_type str( size_type n = 0 ) const; |
(C++11以降) | |
指定されたサブマッチを表す文字列を返します。
もし n == 0 ならば、マッチした式全体を表す文字列が返されます。
もし 0 < n && n < size() ならば、n番目のサブマッチを表す文字列が返されます。
もし 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
[編集] 関連項目
| 指定されたサブマッチを返します。 (public member function) |