參考地址:
ibm手冊http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fregcomp.htm
書籍http://book.douban.com/subject/3794240/
csdn閱讀http://blog.csdn.net/wwwljc/article/details/6159644
c++11正則http://www.cnblogs.com/yejianfei/archive/2012/10/07/2713715.html
幾個Regex(郵箱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(®ex, reg_exp, REG_EXTENDED); if( reti ){ fprintf(stderr, "Could not compile regex\n"); exit(1); }/* Execute regular expression */ reti = regexec(®ex, "wangkangluo1@136.com", 0, NULL, 0); if( !reti ){ puts("Match"); } else if( reti == REG_NOMATCH ){ puts("No match"); } else{ regerror(reti, ®ex, 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(®ex); return 0;}
完