- match_results::cbegin() is an inbuilt function in C++ STL which returns a constant iterator that points to the first match in the match_results object. This iterator cannot modify the contents of the vector.
Syntax:
smatch_name.cbegin()
- Parameters: This function does not accept any parameters.
Return value: This function returns a constant iterator pointing to the first match in the match_results object. The matches contained in the match_results object are always constant.
Note: First element always contains the whole regex match while the others contain the particular Capturing Group.
Below program illustrate the above function.
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
string sp( "geeksforgeeks" );
regex re( "(geeks)(.*)" );
smatch match;
std::regex_match(sp, match, re);
cout << "Match size = " << match.size() << endl;
cout << "matches:" << endl;
for (smatch::iterator it = match.cbegin(); it != match.cend(); ++it)
cout << *it << endl;
return 0;
}
|
Match size=3
matches:
geeksforgeeks
geeks
forgeeks
- smatch::cend() is an inbuilt function in C++ STL which returns a constant iterator that points to the past-the-end match in the match_results object. This iterator cannot modify the contents of the vector.
Syntax:
smatch_name.cend()
- Parameters: This function does not accept any parameters.
Return value: This function returns a constant iterator pointing to the past-the-end match in the match_results object. The matches contained in the match_results object are always constant.
Note: First element always contains the whole regex match while the others contain the particular Capturing Group.
Below program illustrate the above function
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
string sp( "matchresult" );
regex re( "(match)(.*)" );
smatch match;
std::regex_match(sp, match, re);
cout << "Match size = " << match.size() << endl;
cout << "matches:" << endl;
for (smatch::iterator it = match.cbegin(); it != match.cend(); ++it)
cout << *it << endl;
return 0;
}
|
Match size=3
matches:
matchresults
match
results
Please Login to comment...