C + + Regular expression mailbox

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.