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;
    }
  • 相关阅读:
    Python中的yield详解
    Python脚本实现图片加水印
    ajax
    商城页面的增删改查
    事务及完成转账功能
    DBUtils和完善商城页面
    EL和jstl技术
    JSP
    jquery插件
    Cookie和Session
  • 原文地址:https://www.cnblogs.com/jerry1999/p/3677346.html
Copyright © 2011-2022 走看看