Answers for "regex_match Function in C++"

C++
0

regex_match Function in C++

#include <iostream>
#include <string>
#include <regex>
using namespace std;
 
int main () {
 
   if (regex_match ("softwareTesting", regex("(soft)(.*)") ))
      cout << "string:literal => matched\n";
 
   const char mystr[] = "SoftwareTestingHelp";
   string str ("software");
   regex str_expr ("(soft)(.*)");
 
   if (regex_match (str,str_expr))
      cout << "string:object => matched\n";
 
   if ( regex_match ( str.begin(), str.end(), str_expr ) )
      cout << "string:range(begin-end)=> matched\n";
 
   cmatch cm;
   regex_match (mystr,cm,str_expr);
    
   smatch sm;
   regex_match (str,sm,str_expr);
    
   regex_match ( str.cbegin(), str.cend(), sm, str_expr);
   cout << "String:range, size:" << sm.size() << " matches\n";
 
   
   regex_match ( mystr, cm, str_expr, regex_constants::match_default );
 
   cout << "the matches are: ";
   for (unsigned i=0; i<sm.size(); ++i) {
      cout << "[" << sm[i] << "] ";
   }
 
   cout << endl;
 
   return 0;
}
Posted by: Guest on August-19-2021

Browse Popular Code Answers by Language