public member function
<regex>

std::sub_match::str

string_type str() const;
Return string
Returns a string with a copy of the contents referred by the sub_match object.

Parameters

none

Return value

A string with the content referred by the sub_match.

string_type is a member type, defined as an alias of the basic_string type corresponding to the characters being referred by the iterator type used as template argument (BidirectionalIterator). I.e., string for all objects that operate with characters of type char (like csub_match and ssub_match).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// sub_match::str
#include <iostream>
#include <string>
#include <regex>

int main ()
{
  using namespace std::regex_constants;

  std::cmatch m;

  std::regex_match ( "subject", m, std::regex("(sub)(.*)") );

  std::string output = "matches:\n";
  for (std::cmatch::iterator it = m.begin(); it!=m.end(); ++it) {
    output+= it->str() + "\n";
  }

  std::cout << output << std::endl;
  return 0;
}


Output:
matches:
subject
sub
ject

See also

sub_match::operator_string_type