

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- 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 match date with MongoDB $match?
- JavaScript match()
- How to concatenate results in MongoDB?