posts - 58,  comments - 75,  trackbacks - 0
头文件 regex.hpp

常用的类
boost::regex 正则表达式

boost::cmatch 以char数组为容器,存储匹配返回值。
boost::smatch 以std::string为容器,存储匹配返回值。

boost::regex_match 匹配算法
boost::regex_search 查找算法
boost::regex_replace 替换算法

简单例子

#include <iostream>

#include <boost/regex.hpp>

int main( int argc, char* argv[] )
{
    char *buf = "This is boost::regex example";

    boost::regex exampleregex( "boost::regex" );
    boost::cmatch result;

    if( boost::regex_search( buf, result, exampleregex ) )
    {
        std::cout << result.str() << std::endl;
    }

    return 0;
}

注意regex.hpp的包含。要在开发工具中设置boost头文件所在位子。


posted on 2007-12-28 14:01 walkspeed 阅读(9443) 评论(0)  编辑 收藏 引用 所属分类: STL、Boost、范型编程C++语言

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(4)

随笔分类(64)

随笔档案(58)

文章分类(3)

文章档案(3)

相册

收藏夹(9)

C++零碎

好友

搜索

  •  

积分与排名

  • 积分 - 157853
  • 排名 - 163

最新评论

阅读排行榜

评论排行榜