Skip to content

Instantly share code, notes, and snippets.

@RudoCris
Last active May 22, 2016 23:34
Show Gist options
  • Save RudoCris/1b704c9715cfc458ea8bc4caf0a14cf4 to your computer and use it in GitHub Desktop.
Save RudoCris/1b704c9715cfc458ea8bc4caf0a14cf4 to your computer and use it in GitHub Desktop.
Examples of using regex_replacement
#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