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;
int main() {
string str;
while (true) {
cin >> str;
smatch m; //typedef std::match_results<string>
//We can define two groups here to extract the user name and
//domain name
regex e("([[:w:]]+)@([[:w:]]+)\.com");
//search the string for regular expression e and save the
//results to m
bool match = regex_search(str, m, e);
cout << "match size: " << m.size() << endl;
for(int i = 0; i < m.size(); ++i){
//print out the matched results
cout << "m[" << i <<"]: str() = " << m[i].str() <<endl;
}
//prefix is everything before the first matched character
cout <<"m.prefix().str(): " << m.prefix().str() << endl;
//suffic is everything after the last matched character
cout <<"m.suffix().str(): " << m.suffix().str() <<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment