
- 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 operator= in C++
In this article we will be discussing the working, syntax and examples of match_results operator ‘=’ 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 operator ‘=’
Match_results operator = is an equality operator which is used to assign the value to a match_results. Operator = is used to copy or move the elements from one match_results object to another.
Syntax
match_results1 = (match_results2);
Parameters
Another match_results object whose data we have to copy to a match_results object.
Return value
This returns nothing.
Example
Input: string str = "Tutorials Point"; regex R("(Tutorials)(.*)"); smatch Mat_1, Mat_2; regex_match(str, Mat_1, R); Mat_2 = Mat_1; Output: MAT 2 = Tutorials Point Tutorials Point
Example
#include <bits/stdc++.h> using namespace std; int main() { string str = "Tutorials Point"; regex R("(Tutorials)(.*)"); smatch Mat_1, Mat_2; regex_match(str, Mat_1, R); Mat_2 = Mat_1; cout<<"String matches: " << endl; for (smatch::iterator i = Mat_2.begin(); i!= Mat_2.end(); i++) { cout << *i << endl; } }
Output
If we run the above code it will generate the following output −
String matches: Tutorials Point Tutorials Point
Example
#include <bits/stdc++.h> using namespace std; int main() { string str = "Tutorials Point"; regex R_1("(Tutorials)(.*)"); regex R_2("(Po)(int)(.*)"); smatch Mat_1, Mat_2; regex_match(str, Mat_1, R_1); regex_match(str, Mat_2, R_2); smatch Mat; if (Mat_1.size() > Mat_2.size()) { Mat = Mat_1; } else { Mat = Mat_2; } cout<<"string matches " << endl; for (smatch::iterator i = Mat.begin(); i!= Mat.end(); i++) { cout << *i << endl; } }
Output
If we run the above code it will generate the following output −
String matches: Tutorials Point Tutorials Point
- Related Articles
- The Match Operator in Perl
- MYSQL: Can you pull results that match like 3 out of 4 expressions?
- What is the difference between –Match, -Like and –Contains Operator in PowerShell?
- Find the exact match in array without using the $elemMatch operator in MongoDB?
- Analyzing Monitor Results in Postman
- How to concatenate results in MongoDB?
- How to PIVOT results in Oracle?
- How to UNPIVOT results in Oracle?
- deque::operator= and deque::operator[] in C++ STL
- How to match date with MongoDB $match?
- Match in Rust Programming
- Urinalysis: Purposes, Types, Results
- Combine SELECT & SHOW command results in MySQL?
- How to cache query results in Oracle?
- What is a Ternary operator/conditional operator in C#?
- Difference between "new operator" and "operator new" in C++?
