Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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