| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 
 |  
#include <iostream>
#include <string>
#include <regex>
 
 
using namespace std;
 
int main ()
{
  string s ("hello world");
  regex e ("(.*)world");
 
  if (regex_match(s,e))
  {
      cout<<"string matches"<<endl;
 
      // using string/c-string (3) version:
      cout <<regex_replace (s,e,string("planet"))<<endl;
 
      // using range/c-string (6) version:
      string result;
      regex_replace (back_inserter(result), s.begin(), s.end(), e, string ("palnet1"));
      cout <<result<<endl;
 
      // with flags:
      cout <<regex_replace (s,e,string ("planet2"),regex_constants::format_no_copy)<<endl;
  }
 
  else
    cout<<"string does not matches"<<endl;
 
  return 0;
} | 
Partager