#include <string>

#include <vector>

#include <ctime>

#include <numeric>

#include <cmath>

#include <sstream>

#include <thread>

#include <ctime>

#include <iostream>

#include <cstdlib>


#include <regex>


void PrintMatches(std::string str,

        std::regex reg){


    

    std::smatch matches;


    

    std::cout << std::boolalpha;


    

    while(std::regex_search(str, matches, reg)){

        std::cout << "Checked for Results : " <<

                matches.ready() << "\n";


        std::cout << "Are there no matches : " <<

                matches.empty() << "\n";


        std::cout << "Number of matches : " <<

                matches.size() << "\n";


        

        std::cout << matches.str(1) << "\n";


       

        str = matches.suffix().str();


        std::cout << "\n";

    }

}




void PrintMatches2(std::string str,

        std::regex reg){


    

    std::sregex_iterator currentMatch(str.begin(),

            str.end(), reg);


    

    std::sregex_iterator lastMatch;


    

    while(currentMatch != lastMatch){

        std::smatch match = *currentMatch;

        std::cout << match.str() << "\n";

        currentMatch++;

    }

    std::cout << std::endl;


}




int main()

{

    


    std::string str = "The ape was at the apex";


    

    std::regex reg ("(ape[^ ]?)");


    PrintMatches(str,reg);


    


    std::string str2 = "I picked the pickle";


    

    std::regex reg2 ("(pick([^ ]+)?)");


    PrintMatches2(str2,reg2);


    


    std::string str3 = "Cat rat mat fat pat";


    

    std::regex reg3 ("([crmfp]at)");


    PrintMatches2(str3,reg3);


    

    std::regex reg4("[C-Fc-f]at");

    PrintMatches2(str3,reg4);


    

    std::regex reg5("[^Cr]at");

    PrintMatches2(str3,reg5);


    

    std::string str6 = "Cat rat mat fat pat";

    std::regex reg6("[Cr]at");


    

    std::string owlFood = std::regex_replace(str6,reg6,"Owl");

    std::cout << owlFood << "\n";


    


    std::string str7 = "F.B.I. I.R.S. CIA";

    std::regex reg7("([^ ]\..\..\.)");

    PrintMatches2(str7,reg7);



    

    std::string str8 = "This is a\n multiline string\n"

            "that has many lines";

    std::regex reg8("\n");

    std::string noLBStr = std::regex_replace(str8,reg8," ");

    std::cout << noLBStr << "\n";


   


   

    std::string str9 = "12345";

    std::regex reg9("\\d");

    PrintMatches2(str9, reg9);


    

    std::string str10 = "123 12345 123456 1234567";


    

    std::regex reg10("\\d{5,7}");

    PrintMatches2(str10, reg10);


   

    std::string str11 = "412-555-1212";


    

    std::regex reg11("\\w{3}-\\w{3}-\\w{4}");

    PrintMatches2(str11, reg11);


    


    std::string str12 = "Toshio Muramatsu";


    

    std::regex reg12("\\w{2,20}\\s\\w{2,20}");

    PrintMatches2(str12, reg12);


    

    std::string str13 = "a as ape bug";


    std::regex reg13("a[a-z]+");

    PrintMatches2(str13, reg13);


    


    std::string str14 = "db@aol.com m@.com @apple.com db@.com";


    std::regex reg14("[\\w._%+-]{1,20}@[\\w.-]{2,20}.[A-Za-z]{2,3}");

    PrintMatches2(str14, reg14);



    


    return 0;

}