public member function
<regex>

std::match_results::suffix

const_reference suffix() const;
Return suffix
Returns a reference to a sub_match object representing the character sequence that follows the end of the matched sequence in the target sequence.

The match_results object shall be ready, which happens after it has been passed as the proper argument in a call to either regex_match or regex_search.

Parameters

none

Return value

A reference to the sub_match object describing the suffix.

Member type const_reference is an alias of the reference to the appropriate const sub_match type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// match_results::prefix/suffix
// - using smatch, a standard alias of match_results<string::iterator>
#include <iostream>
#include <string>
#include <regex>

int main ()
{
  std::string s ("there is a needle in this haystack");
  std::smatch m;
  std::regex e ("needle");

  std::cout << "searching for needle in [" << s << "]\n";
  std::regex_search ( s, m, e );

  if (m.ready()) {
    std::cout << m[0] << " found!\n";
    std::cout << "prefix: [" << m.prefix() << "]\n";
    std::cout << "suffix: [" << m.suffix() << "]\n";
  }

  return 0;
}


Output:
searching for needle in [there is a needle in this haystack]
needle found!
prefix: [there is a ]
suffix: [ in this haystack]


See also