This file contains 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<vector> | |
#include<regex> | |
using namespace std; | |
//regex_token_iterator: pointing to a sub match | |
int main() { | |
string str = "zhangxm01@gmail.com; zhan@163.com; zhan_j@yahoo.com"; | |
regex e("([[:w:]]+)@([[:w:]]+)\.com"); | |
//regex iterator | |
sregex_token_iterator pos(str.cbegin(), str.cend(), e); | |
//default constructor defines past-the-end iterator | |
sregex_token_iterator end; | |
for(; pos != end; ++pos){ | |
//str() cannot have any parameters | |
cout << "Matched: " << pos->str() << 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