C ++ regex
Use C ++ regex to determine numbers, real numbers, ip addresses, emails, words, phone numbers, dates, and other formats
#include "check.h"#include
#include
using namespace std;
/// Determine whether all values are digits bool all_digit (const string & s) {regex r ("^ [0-9] * $"); return regex_match (s, r );}
/// Determine the word bool all_alpha (const string & s) {regex r ("^ [: alpha:] * $"); return regex_match (s, r );}
/// Determine whether it is a word or number bool all_alnum (const string & s) {regex r ("^ [[: alnum:] * $"); return regex_match (s, r );}
/// Determine the integer bool is_int (const string & s) {regex r ("^ [-]? (0 | ([1-9] [0-9] *) $ "); return regex_match (s, r );}
/// Determine the real number bool is_float (const string & s) {regex r ("^ -? (0 | ([1-9] [0-9] *) \. [0-9] + $ "); return regex_match (s, r );}
/// Determine ipbool is_ip (const string & s) {regex r ("^ (25 [0-5]) | (2 [0-4] [0-9]) | (1 [0-9] {2 }) | ([1-9] [0-9]?) | 0) \.) {3 }"
"((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|(([1-9][0-9]?)|0)))$"); return regex_match(s,r);}
/// Determine the phone number, starting with 0 or 1, and 11 digits form bool is_phone (const string & s) {regex r ("^ [01] [0-9] {10} $"); return regex_match (s, r );}
/// Determine the bool is_date (const string & s) between the 1900-2999 years) {regex r ("^ [12] [0-9] {3}-(0 [1-9]) | (1 [0-2]) -(0 [1-9]) | ([12] [0-9]) | (3 [01]) $ "); return regex_match (s, r );}
/// Determine the email address bool is_mail (const string & s) {regex r ("^ [[: alnum:] + @ [[: alnum:] + \\. [a-z] + $ "); return regex_match (s, r );}