Matching Specific String

  • + 0 comments
    #include "bits/stdc++.h"
    using namespace std;
    
    
    int main() {
        string s;
        getline(cin,s);
        regex r("hackerrank");
        if(regex_search(s,r)){
            auto word_begin=sregex_iterator(s.begin(),s.end(),r);
            auto word_end=sregex_iterator();
            cout<<"Number of matches : "<<distance(word_begin, word_end);
        }
        return 0;
    }