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