regex match function in c 2b 2b

Solutions on MaxInterview for regex match function in c 2b 2b by the best coders in the world

showing results for - "regex match function in c 2b 2b"
Carlton
25 Jul 2016
1#include <iostream>
2#include <string>
3#include <regex>
4using namespace std;
5 
6int main () {
7 
8   if (regex_match ("softwareTesting", regex("(soft)(.*)") ))
9      cout << "string:literal => matched\n";
10 
11   const char mystr[] = "SoftwareTestingHelp";
12   string str ("software");
13   regex str_expr ("(soft)(.*)");
14 
15   if (regex_match (str,str_expr))
16      cout << "string:object => matched\n";
17 
18   if ( regex_match ( str.begin(), str.end(), str_expr ) )
19      cout << "string:range(begin-end)=> matched\n";
20 
21   cmatch cm;
22   regex_match (mystr,cm,str_expr);
23    
24   smatch sm;
25   regex_match (str,sm,str_expr);
26    
27   regex_match ( str.cbegin(), str.cend(), sm, str_expr);
28   cout << "String:range, size:" << sm.size() << " matches\n";
29 
30   
31   regex_match ( mystr, cm, str_expr, regex_constants::match_default );
32 
33   cout << "the matches are: ";
34   for (unsigned i=0; i<sm.size(); ++i) {
35      cout << "[" << sm[i] << "] ";
36   }
37 
38   cout << endl;
39 
40   return 0;
41}
42