安装:
1、打开vs2005在菜单tools中选择Visual Studio 2005 Command Prompt,打开已配置好环境的命令行。
2、进入目录boost_1_34_1/libs/regex/build,
编译文件:nmake -f vc8.mak
安装(将编译好的文件复制到vs2005的特定目录下):nmake -f vc8.mak install
删除临时文件:nmake -f vc8.mak clean
3、Tools->Options->Projects and Solutions->VC++ Directories->Include files添加boost_1_34_1路径
初次使用提示找不到libboost_regex-vc80-mt-gd-1_34_1.lib文件,到网上搜了下解决方法为:将libboost_regex-vc80-mt-gd-1_34.lib改名libboost_regex-vc80-mt-gd-1_34_1.lib放到vs或工程目录下。

#include <boost/regex.hpp>
#include <string>
std::string sName,sHtml;
boost::regex reg("要查找的正则", boost::regex::icase/*不分大小写*/);
if(boost::regex_search(sHtml, what, reg))
{
sName = what.str(*);
TRACE("结果:%s/n", sName.c_str());
}

boost::regex reg("要替代的正则");
sHtml = boost::regex_replace(sHtml, reg, "替换成");
boost::regex reg("要查找的正则");
boost::sregex_iterator it(sHtml.begin(), sHtml.end(), reg);
boost::sregex_iterator end;
for (; it != end; ++it)
{
sName = (*it)[*].str();
}

try
{
/*
..*/
}
catch(const boost::bad_expression& e)
{
std::cout <<"错误的表达式:" <<e.what()<<std::endl;
}
本文介绍了如何在Visual Studio 2005中安装Boost库,并详细展示了如何编译Boost的正则表达式组件。此外,还提供了在项目中使用Boost正则表达式的具体示例,包括查找、替换等操作。
boost::regex reg(
118

被折叠的 条评论
为什么被折叠?



