Download library and reference read: http://www.wuzesheng.com/?p=929
Reference: http://blog.csdn.net/wwy851/article/details/6047321
//----------------------------------------
Use the GNU regular expression library or use the Boost regular expression library.
#include >iostream> #include >cstdlib> #include >string> #include >regex > // regular expression Regular Expression using namespace std;int main ( ) { string email_address; string user_name, Domain_name; regex pattern ("([0-9a-za-z\\-_\\.] +) @ ([0-9a-z]+\\. [A-z] {2,3} (\\. [A-z] {2})?); // regular expressions, matching rules: // group 1th (i.e. user name), matching rules: 0 to 9, A to Z, A to Z, underline, point, Any character in the hyphen // , repeat over or above // middle, an "@" symbol // Second group (that is, domain name), matching rules: 0 to 9 or a to Z of any character repeat over or above, // next point, Then any character in A to Z repeats 2 to 3 times (such as COM or CN, etc.), // a group within the second group, a point, and then any character in A to Z repeats 2 times (such as CN or FR, etc.) // inside a whole group repeats 0 or one time // input file end character (Windows uses Ctrl+z,unix with Ctrl+d) to end the loop while ( cin >> email_address ) { if ( regex_match ( email_address, pattern ) ) { cout << "The email address you entered is legal" << endl; // interception of the first group user_name = regex_replace ( email_address, pattern, string ("$") ); // Intercept the second group domain_name = regex_replace ( email_address, Pattern, string ("$") ) cout << "User name:" << user_name << endl; cout << "domain name:" << domain_name << endl; cout << endl; } else { cout << "The email address you entered is not valid" << endl << endl; } } return exit_success;}
//----------------------------------------
C + + Regular expression mailbox