-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathregexReplace.cpp
31 lines (21 loc) · 860 Bytes
/
regexReplace.cpp
1
2
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
#include <regex>
#include <iomanip>
#include <iostream>
#include <string>
int main(){
std::cout << '\n';
std::string future{"Future"};
int len = sizeof(future);
std::string unofficialStandardName{"The unofficial name of the new C++ standard is C++0x."};
std::cout << std::setw(len) << std::left << "Past: " << unofficialStandardName << '\n';
// replace C++0x with C++11
std::regex rgxCpp(R"(C\+\+0x)");
std::string newCppName{"C++11"};
std::string newStandardName{std::regex_replace(unofficialStandardName, rgxCpp, newCppName)};
// replace unofficial with official
std::regex rgxOff{"unofficial"};
std::string makeOfficial{"official"};
std::string officialName{std::regex_replace(newStandardName, rgxOff, makeOfficial)};
std::cout << std::setw(len) << std::left << "Now: " << officialName << '\n';
std::cout << '\n';
}