Open In App

match_results cbegin() add cend() in C++ STL

smatch_name.cbegin()




// C++ program to illustrate the
// match_result function
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string sp("geeksforgeeks");
    regex re("(geeks)(.*)");
 
    smatch match;
 
    // we can use member function on match
    // to extract the matched pattern.
    std::regex_match(sp, match, re);
 
    // The size() member function indicates the
    // number of capturing groups plus one for the overall match
    // match size = Number of capturing group + 1
    // (.*) which "forgeeks" ).
    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_name.cend()




// C++ program to illustrate the
// match_results cend() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string sp("matchresult");
    regex re("(match)(.*)");
 
    smatch match;
 
    // we can use member function on match
    // to extract the matched pattern.
    std::regex_match(sp, match, re);
 
    // The size() member function indicates the
    // number of capturing groups plus one for the overall match
    // match size = Number of capturing group + 1
    // (.*) which "results" ).
    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

Article Tags :
C++