C ++ regex

Source: Internet
Author: User

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 );}


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.