boost用正則表達式驗證ip地址合法

// 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;  
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章