Skip to content

Instantly share code, notes, and snippets.

@zhangxiaomu01
Created July 11, 2019 22:10
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/cafba0f664b8048be39733375d30c3fb to your computer and use it in GitHub Desktop.
Save zhangxiaomu01/cafba0f664b8048be39733375d30c3fb to your computer and use it in GitHub Desktop.
#include<iostream>
#include<string>
#include<vector>
#include<regex>
using namespace std;
//We can use regular expression iterator here!
int main() {
string str = "zhangxm01@gmail.com; zhan@163.com; zhan_j@yahoo.com";
regex e("([[:w:]]+)@([[:w:]]+)\.com");
//regex iterator
sregex_iterator pos(str.cbegin(), str.cend(), e);
//default constructor defines past-the-end iterator
sregex_iterator end;
for(; pos != end; ++pos){
cout << "Matched: " << pos->str(0) << endl;
cout << "User Name: " << pos->str(1) << endl;
cout << "Domain: " << pos->str(2) <<endl;
cout << endl;
}
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment