
- 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 size() in C++ STL
In this article we will be discussing the working, syntax and examples of match_results::size() 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::size()?
match_results::size() function is an inbuilt function in C++ STL, which is defined in <regex> header file. size() is used to get the number of matches of the match_results object associated with it. This function returns a size_type value that is the number of matches and sub-matches are there in the object associated with the function.
Syntax
smatch_name.size();
Parameters
This function accepts no parameters.
Return value
This function returns size_type size or the number of the matches and sub matches of the match_results object.
Example
Input: string str = "Tutorials Point"; regex R("(Tutorials)(.*)"); smatch Mat; regex_match(str, Mat, R); Mat.size(); Output: 3
Example
#include <bits/stdc++.h> using namespace std; int main() { string str = "Tutorials Point"; regex R("(Tutorials)(.*)"); smatch Mat; regex_match(str, Mat, R); cout<<"Size is: " << Mat.size() << endl; return 0; }
Output
If we run the above code it will generate the following output −
Size is: 3
Example
#include <bits/stdc++.h> using namespace std; int main() { string str = "Tutorials Point Tutorials"; regex R("(Tutorials)(.*)"); smatch Mat; regex_match(str, Mat, R); for (int i = 0; i < Mat.size(); i++) { cout <<"length of "<<Mat.length(i)<< endl; } return 0; }
Output
If we run the above code it will generate the following output −
length of 25 length of 9 length of 16
- Related Articles
- match max_size() function in C++ STL
- map::size() in C++ STL
- unordered_multimap size() function in C++ STL
- list size() function in C++ STL
- multimap size() function in C++ STL
- multiset size() in C++ STL with Examples
- deque::empty() and deque::size() in C++ STL
- queue::empty() and queue::size() in C++ STL
- stack empty() and stack size() in C++ STL
- MYSQL: Can you pull results that match like 3 out of 4 expressions?
- Maximum of all Subarrays of size k using set in C++ STL
- Analyzing Monitor Results in Postman
- How to concatenate results in MongoDB?
- How to PIVOT results in Oracle?
- How to UNPIVOT results in Oracle?
