Boost Regular Expression verification email address

Source: Internet
Author: User

The most common verification is email address verification. Websites are common. Various web scripts also use regular expressions "(Regular Expression) Verify the email address we entered to determine whether the email address is valid. Some can also separate the username and domain name. Use nowC ++The language implements email address verification.Program, Which isBoostRegular Expression Library.

Source codeAs follows:CodeAlready inG ++ 4.6.

 /*  * RegEx. CPP-use a regular expression to verify the email address ** boost regular expression ** copyright ye Jianfei 2012 * Compilation command: * g ++ RegEx. CPP-O RegEx-wall-lboost_regex *  */  # Include <Iostream># Include <Cstdlib> # Include <String> # Include <Boost/RegEx. HPP> //  Regular Expression  Using   Namespace  STD;  Using   Namespace  Boost;  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 Expression, matching rules:  //  Group 1 (username), matching rules: 0 to 9, A to Z, A to Z, underline, dot, and hyphen  //  Any character of, repeated once or more  //  In the middle, a "@" symbol  // The second group (that is, the domain name), matching rules: 0 to 9 and any character in A to Z repeat or above,  //  Next, any character in A to Z should be repeated 2 to 3 times (such as com or CN ),  //  A group in the second group, a vertex, and any character from A to Z Repeat twice (such as CN or fr)  //  The entire group is repeated for zero or one time.  //  Enter the file terminator (CTRL + Z for Windows and CTRL + D for UNIX) to end the loop.      While (CIN> Email_address ){  If  (Regex_match (email_address, pattern) {cout < "  The email address you entered is valid.  " < Endl;  //  Intercept Group 1 User_name = regex_replace (email_address, pattern, String ( "  $1  "  ));  //  Intercept Group 2 Domain_name = regex_replace (email_address, pattern,String ( "  $2  "  ); Cout < "  User name:  " <User_name < Endl; cout < "  Domain Name:  " <Domain_name < Endl; cout < Endl ;} Else  {Cout < "  The email address you entered is invalid.  " <Endl < Endl ;}}  Return  Exit_success ;} 

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.