zoukankan      html  css  js  c++  java
  • 正则表达式校验IP地址

    #include <vcl.h>
    #include <pcre.h>

    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;
    }
  • 相关阅读:
    pod间访问
    Android地图下钻(坑我好久)
    学习进度23
    学习进度22
    人月神话读后感03
    团队介绍
    人月神话读后感02
    学习进度21
    学习进度20
    学习进度19
  • 原文地址:https://www.cnblogs.com/jerry1999/p/3677346.html
Copyright © 2011-2022 走看看