您当前的位置: 首页 >  正则表达式

蓝不蓝编程

暂无认证

  • 3浏览

    0关注

    706博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

正则表达式校验IP地址

蓝不蓝编程 发布时间:2013-03-01 22:35:54 ,浏览量:3

#include #include

bool isIPValid(UnicodeString ipStr)

{ char ipAddrPattern[]="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$";     const char      *pszErr;     int             nErrOffset; pcre *re = pcre_compile(ipAddrPattern,0,&pszErr,&nErrOffset,NULL);     if(re==NULL)     { return false; } const int vectorSize = 30; int ovector[vectorSize];    // 数量由szReg决定,大致为(括号对数+1)*3,可以用pcre_info获得或者直接留大一点。 int rc = pcre_exec(re, NULL, ipStr.c_str(), ipStr.Length(), 0, ovector, vectorSize);   // 执行匹配 free(re); if(rc>=0) return true; else      return false; }
关注
打赏
1639405877
查看更多评论
立即登录/注册

微信扫码登录

0.0376s