boost用正则表达式验证ip地址合法

来源:互联网 发布:linux tar 打包文件夹 编辑:程序博客网 时间:2024/05/09 06:46
// boostTest.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream>   #include <boost/xpressive/xpressive_dynamic.hpp>//BOOST用正则表达式验证ip地址合法bool CheckIP(const char *ip){using namespace boost::xpressive;/* 定义正则表达式 */cregex reg_ip = cregex::compile("(25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])[.](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[.](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[.](25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])"); return regex_match(ip, reg_ip);}int _tmain(int argc, _TCHAR* argv[])  {  std::wcout<<"ip:"<<CheckIP("1247.0.0.1");getchar();  return 0;  }

0 0
原创粉丝点击