Skip to content

Instantly share code, notes, and snippets.

@zhangxiaomu01
Created July 11, 2019 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangxiaomu01/b320f4f64f899ff2609915910e4fd33b to your computer and use it in GitHub Desktop.
Save zhangxiaomu01/b320f4f64f899ff2609915910e4fd33b to your computer and use it in GitHub Desktop.
#include<iostream>
#include<string>
#include<vector>
#include<regex>
using namespace std;
//regex_replace
int main() {
string str = "zhangxm01@gmail.com; zhan@163.com; zhan_j@yahoo.com";
regex e("([[:w:]]+)@([[:w:]]+)\.com");
//$1 and $2 represents the group 1 and group 2 in the regex
cout <<regex_replace(str, e, "$1 is on $2") << endl;;
//We can add more flags in the regex_replace function
cout << regex_replace(str, e, "$1 is on $2", regex_constants::format_no_copy|regex_constants::format_first_only);
cout<< endl;
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment