<regex>

public member function
<regex>

std::match_results::empty

bool empty() const;
Test whether object has no matches
Returns true if the match_results object contains no matches.

When the object is default-constructed, this value is initialized to true. If a call to regex_match or regex_search with the match_results object as argument finds at least one match, this value is set to false. If no matches are found, it is set to true.

To check whether the object has already been filled by one of these functions (without distinguishing whether the pattern was successfully matched or not), you can use match_results::ready.

Parameters

none

Return value

true if the object contains no matches. false if at least contains one.

Example

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

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

  std::string s ("Subject");
  std::regex e1 ("sub.*");
  std::regex e2 ("sub.*", ECMAScript | icase);

  std::smatch m1,m2;

  std::regex_match ( s, m1, e1 );
  std::regex_match ( s, m2, e2 );

  std::cout << "e1 " << ( m1.empty() ? "did not match" : "matched" ) << std::endl;
  std::cout << "e2 " << ( m2.empty() ? "did not match" : "matched" ) << std::endl;

  return 0;
}


Output:
e1 did not match
e2 matched

See also