【转】boost正则表达式库简单介绍
2010-09-27 05:36
260 查看
转自:http://www.cppblog.com/walkspeed/archive/2007/12/28/39823.html
头文件 regex.hpp
常用的类
boost::regex 正则表达式
boost::cmatch 以char数组为容器,存储匹配返回值。
boost::smatch 以std::string为容器,存储匹配返回值。
boost::regex_match 匹配算法
boost::regex_search 查找算法
boost::regex_replace 替换算法
简单例子
#include
#include
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头文件所在位子。
头文件 regex.hpp
常用的类
boost::regex 正则表达式
boost::cmatch 以char数组为容器,存储匹配返回值。
boost::smatch 以std::string为容器,存储匹配返回值。
boost::regex_match 匹配算法
boost::regex_search 查找算法
boost::regex_replace 替换算法
简单例子
#include
#include
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头文件所在位子。
相关文章推荐
- java正则表达式简单介绍
- oracle的正则表达式(regular expression)简单介绍从oarcle10g开始支持
- JavaScript正则表达式的简单介绍和一些小例子(一)
- 第7章 sed、gawk介绍与正则表达式-----------(sed编辑器简单使用)
- oracle的正则表达式(regular expression)简单介绍——转贴
- 正则表达式的简单介绍和string.replace的用法
- c++使用boost正则表达式的简单用法
- xgboost+python参数介绍的简单使用
- 正则表达式的简单介绍
- js使用正则(简单介绍)
- 正则简单介绍和使用RegexBuddy工具
- 简单介绍一下C#正则表达式
- oracle(10G)的正则表达式(regular expression)简单介绍
- 限制QLineEdit的数值输入范围(QT正则表达式方法),顺便简单介绍下QT正则表达式方法
- python 爬虫003-正则表达式简单介绍
- 正则表达式的简单介绍
- BOOST正则表达式库处理中文
- boost::variant的简单介绍
- oracle的正则表达式(regular expression)简单介绍
- 第7章 sed、gawk介绍与正则表达式-----------(gawk编辑器简单使用)