std::match_results::str

From Cppreference

Jump to: navigation, search
difference_type str( size_type sub = 0 ) const;
(C++11 feature)

[edit] Parameters

sub - Indicates the sub_match.

[edit] Return value

Returns the indicated match or sub-match within the target sequence a std::basic_string of the underlying character type.

[edit] Example

#include <iostream>
#include <regex>
#include <string>
 
int main()
{
  std::regex re("a(a)*b");
  std::string target("aaab");
  std::smatch sm;
 
  std::regex_match(target, sm, re);
  std::cout << sm.str(1) << '\n';
}

Output:

aaa