Subtotal of c Regular Expression matching

Source: Internet
Author: User

Reference address:

IBM manual http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/index.jsp? Topic=%2frtref%2fregcomp.htm

Books http://book.douban.com/subject/3794240/

Csdn read http://blog.csdn.net/wwwljc/article/details/6159644

C ++ 11 regular http://www.cnblogs.com/yejianfei/archive/2012/10/07/2713715.html

Match several regular expressions (email, IPv4:

# Include <sys/types. h> # Include <RegEx. h> # Include <Stdio. h> Int Main ( Int Argc, Char * Argv []) {regex_t RegEx; Int  Reti;  Char Msgbuf [ 100  ];  Const   Char * Reg_exp = "  ^ \ W + ([-+.] \ W +) * @ \ W + ([-.] \ W + )*\\. \ W + ([-.] \ W +) * $  "  ;
// IPv4'^ (25 [0-5] | 2 [0-4] [0-9] | 1 [0-9] [0-9] | [1-9] [0-9] | [0-9]) \\.) {3} (25 [0-5] | 2 [0-4] [0-9] | 1 [09] [0-9] | [1-9] [0 -9] | [0-9]) $'
/* Compile Regular Expression */ RETI = Regcomp (& RegEx, reg_exp, reg_extended ); If (RETI) {fprintf (stderr, " Cocould not compile RegEx \ n " ); Exit ( 1 );} /* Execute Regular Expression */ RETI = Regexec (& RegEx, " Wangkangluo1@136.com " , 0 , Null, 0 ); If (! RETI) {puts ( " Match " );} Else If (RETI = Reg_nomatch) {puts ( " No match " );} Else {Regerror (RETI, & RegEx, msgbuf, Sizeof (Msgbuf); fprintf (stderr, " RegEx match failed: % s \ n " , Msgbuf); exit ( 1 );} /* Free compiled regular expression if you want to use the regex_t again */ Regfree ( & RegEx ); Return 0 ;}

 

End

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.