std::match_results<BidirIt,Alloc>::str
來自 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 成員函式) |