c 2b 2b program to demonstrate the regex replace 28 29 function

Solutions on MaxInterview for c 2b 2b program to demonstrate the regex replace 28 29 function by the best coders in the world

showing results for - "c 2b 2b program to demonstrate the regex replace 28 29 function "
Grégoire
04 May 2017
1#include <iostream> 
2#include <string> 
3#include <regex> 
4#include <iterator> 
5using namespace std; 
6   
7int main() 
89    string mystr = "This is software testing Help portal \n"; 
10     
11    cout<<"Input string: "<<mystr<<endl;
12       
13    // regex to match string beginning with 'p' 
14    regex regexp("p[a-zA-z]+"); 
15    cout<<"Replace the word 'portal' with word 'website' : "; 
16    // regex_replace() for replacing the match with the word 'website'  
17    cout << regex_replace(mystr, regexp, "website"); 
18     
19    string result; 
20       
21    cout<<"Replace the word 'website' back to 'portal': ";
22    // regex_replace( ) for replacing the match back with 'portal' 
23    regex_replace(back_inserter(result), mystr.begin(), mystr.end(), 
24                  regexp,  "portal"); 
25   
26    cout << result; 
27   
28    return 0; 
29}
30