Last active
May 22, 2016 23:34
-
-
Save RudoCris/1b704c9715cfc458ea8bc4caf0a14cf4 to your computer and use it in GitHub Desktop.
Examples of using regex_replacement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <regex> | |
using namespace std; | |
int main () { | |
// replace first x => ks | |
string str = "Thanx Texas\n"; | |
cout << str; | |
regex x("x"); | |
string ks = "ks"; | |
cout << regex_replace (str, x, ks, regex_constants::format_first_only) << endl; | |
// replace ed => ing, ph => f | |
str = "I was loved, I was trusted, I was losed, I was philled\n"; | |
cout << str; | |
regex ed("ed"), ph("ph"); | |
string ing = "ing", f = "f"; | |
str = regex_replace (str, ed, ing); | |
cout << regex_replace (str, ph, f) << endl;; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment