我的学习园地

昨夜西风凋碧树,独上高楼,望尽天涯路。

  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  14 随笔 :: 0 文章 :: 36 评论 :: 0 Trackbacks


安装:
  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; 
}
posted on 2008-01-17 13:07 冷夜月 阅读(3485) 评论(0)  编辑 收藏 引用 所属分类: C/C++
只有注册用户登录后才能发表评论。