一:編譯
boost的正則表達式需要編譯(如果不需要全部Boost的功能的話,請不要build all boost,那會花掉好幾個小時。我推薦僅僅build需要的庫就好。)
原有的boost 1.33似乎使用vc8編譯的時候有問題。下載boost 1.34.1,使用“Visual Studio 2005 Command Prompt”,進入到boost_1_34_1\libs\regex\build:
nmake vc8.mak
OK,生成的文件在vc80下。
二:學習正則表達式
http://www.shnenglu.com/Files/shootingstars/deelx_zh.rar不錯的正則表達式的學習資料,順便推薦一下:
http://www.regexlab.com/
這個站長還與我有個一信之緣(我寫的
P2P之UDP穿透NAT的原理與實現(xiàn)(附源代碼))。站長的這個正則庫在CodeProject獲得了不錯的評價。
三:簡單的例子
std::string regstr = "a+";
boost::regex expression(regstr);
std::string testString = "aaa";
// 匹配至少一個a
if( boost::regex_match(testString, expression) )
{
std::cout<< "Match" << std::endl;
}
else
{
std::cout<< "Not Match" << std::endl;
}