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 C ++ implements the email address verification Program , C ++ 11 Standard STL regular expression.
Source codeAs follows:CodeAlready inVisual Studio 2010.G ++ 4.6Not SupportedC ++ 11OfSTLRegular Expression,G ++ 4.6Can be compiled on, but the runtime error is thrownRegex_errorException. Therefore, if you wantG ++ 4.6Use a regular expression.GNURegular Expression library orBoostRegular Expression Library.
/* * RegEx. CPP-use regular expressions to verify the email address ** C ++ 11 standard STL Regular Expression *** copyright ye Jianfei 2012 ** compilation command: * Cl RegEx. CPP/ehs/ link/out: regex.exe * */ # Include <Iostream> # Include <Cstdlib> # Include <String> # Include <RegEx> // 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 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 or 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 ;}