
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
match_results empty() in C++ STL
In this article we will be discussing the working, syntax and examples of match_results::empty() function in C++ STL.
What is a match_results in C++ STL?
std::match_results is a specialized container-like class which is used to hold the collection of character sequences which are matched. In this container class a regex match operation finds the matches of the target sequence.
What is match_results::empty()?
match_results::empty() function is an inbuilt function in C++ STL, which is defined in <regex> header file. empty() checks whether the smatch object which is associated is empty or having some match values in it. empty() returns true if the match object is empty or having no matches, if the container is having some values then the function will return false.
Syntax
smatch_name.empty();
Parameters
This function accepts no parameter.
Return value
This function returns Boolean value true if the match object is empty, or there are no matches in the container, else returns false if the match object are having some values or there are some matches available.
Example
Input: std::smatch; smatch.empty(); Output: true
Example
#include<bits/stdc++.h> using namespace std; int main() { string str("Tutorials"); regex R_1("Points.*"); regex R_2("Tutorials.*"); smatch Mat_1, Mat_2; regex_match(str, Mat_1, R_1); regex_match(str, Mat_2, R_2); if (Mat_1.empty()) { cout<<"String doesn't matches with Regex-1" << endl; } else { cout << "String matches with Regex-1" << endl; } if (Mat_2.empty()) { cout << "String doesn't matches with Regex-2" << endl; } else { cout << "String matches with Regex-1" << endl; } return 0; }
Output
If we run the above code it will generate the following output −
String doesn't matches with Regex-1 String matches with Regex-1
- Related Articles
- map::empty() in C++ STL
- match max_size() function in C++ STL
- list empty() function in C++ STL
- multiset empty() function in C++ STL
- multimap empty() function in C++ STL
- forward_list::front() and forward_list::empty() in C++ STL
- deque::empty() and deque::size() in C++ STL
- queue::empty() and queue::size() in C++ STL
- stack empty() and stack size() in C++ STL
- What does LINQ return when the results are empty in C#?
- MYSQL: Can you pull results that match like 3 out of 4 expressions?
- Analyzing Monitor Results in Postman
- How to concatenate results in MongoDB?
- How to PIVOT results in Oracle?
- How to UNPIVOT results in Oracle?
