- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 begin() and end() function in C++ STL
In this article we will be discussing the working, syntax and examples of match_results::begin() and match_results::end() functions 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::begin()?
match_results::begin() function is an inbuilt function in C++ STL, which is defined in <regex> header file. This function returns an iterator which is pointing to the first element in the match_results object. The match_results::begin() and match_results::end() are together used to give the range of the match_results container.
Syntax
match_name.begin();
Parameters
This function accepts no parameter.
Return value
This function returns an iterator which is pointing to the first element of the match_results container.
Example
Input: std::string str("TutorialsPoint"); std::smatch Mat; std::regex re("(Tutorials)(.*)"); std::regex_match ( str, Mat, re ); Mat.begin(); Output: T
Example
#include <iostream> #include <string> #include <regex> int main () { std::string str("Tutorials"); std::smatch Mat; std::regex re("(Tuto)(.*)"); std::regex_match ( str, Mat, re ); std::cout<<"Match Found: " << std::endl; for (std::smatch::iterator i = Mat.begin(); i!= Mat.end(); ++i) { std::cout << *i << std::endl; } return 0; }
Output
If we run the above code it will generate the following output −
Match Found Tutorials Tuto rials
What is match_results::end()?
match_results::end() function is an inbuilt function in C++ STL, which is defined in <regex> header file. This function returns an iterator which is pointing to the position next to the last element in the match_results object. The match_results::begin() and match_results::end() are togetherly used to give the range of the match_results container.
Syntax
smatch_name.begin();
Parameters
This function accepts no parameter.
Return value
This function returns an iterator which is pointing to the element past the end of the match_results container.
Input: std::string str("TutorialsPoint"); std::smatch Mat; std::regex re("(Tutorials)(.*)"); std::regex_match ( str, Mat, re ); Mat.end(); Output: m //Random value which is past to the end of the container.
Example
#include <iostream> #include <string> #include <regex> int main () { std::string str("Tutorials"); std::smatch Mat; std::regex re("(Tuto)(.*)"); std::regex_match ( str, Mat, re ); std::cout<<"Match Found: " << std::endl; for (std::smatch::iterator i = Mat.begin(); i!= Mat.end(); ++i) { std::cout << *i << std::endl; } return 0; }
Output
If we run the above code it will generate the following output −
Match Found Tutorials Tuto rials
- Related Articles
- multiset begin() and end() function in C++ STL
- map::begin() and end() in C++ STL
- set::begin() and set::end() in C++ STL
- vector::begin() and vector::end() in C++ STL
- list begin( ) and list end( ) in C++ STL
- forward_list::begin() and forward_list::end() in C++ STL
- deque::begin() and deque::end in C++ STL
- multimap::begin() and multimap::end() in C++ STL
- match max_size() function in C++ STL
- list end() function in C++ STL
- BEGIN and END Blocks in Perl
- If$\begin{bmatrix}x 3\\ 0 2y-x\end{bmatrix} +\begin{bmatrix}1 2\\ 0 -2\end{bmatrix} =\begin{bmatrix}4 5\\ 0 3\end{bmatrix}$.Find the value of x and y.
- How can we create MySQL stored procedures without ‘BEGIN’ and ‘END’?
- end() function in PHP
- Set cbegin() and cend() function in C++ STL
