| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Classes | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Algorithms | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Iterators | ||||
(C++11) | ||||
(C++11) | ||||
| Exceptions | ||||
(C++11) | ||||
| Traits | ||||
(C++11) | ||||
| Constants | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Regex Grammar | ||||
(C++11) |
| Member functions | ||||
| State | ||||
| Element access | ||||
match_results::str | ||||
| Iterators | ||||
| Format | ||||
| Modifiers | ||||
| Non-member functions | ||||
(until C++20) | ||||
string_type str( size_type n=0)const; | (since C++11) | |
Returns a string representing the indicated sub-match.
Ifn==0, a string representing entire matched expression is returned.
If0< n&& n< size(), a string representingnth sub-match is returned.
ifn>= size(), a string representing the unmatched match is returned.
The call is equivalent tostring_type((*this)[n]);
ready() must betrue. Otherwise, the behavior is undefined.
Contents |
| n | - | integral number specifying which match to return |
Returns a string representing the specified match or 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.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';}
Output:
entire match: aaabsubmatch #1: aentire match: aaabsubmatch #1: aa
| returns specified sub-match (public member function)[edit] |