c正则匹配小计

参考地址:

ibm手册http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fregcomp.htm

书籍http://book.douban.com/subject/3794240/

csdn阅读http://blog.youkuaiyun.com/wwwljc/article/details/6159644

c++11正则http://www.cnblogs.com/yejianfei/archive/2012/10/07/2713715.html

几个正则表达式(邮箱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, "Could 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; }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值