官方当前文档
http://www.boost.org/doc/libs/1_57_0/libs/regex/doc/html/index.html
头文件
boost/regex.hpp
链接库
-lboost_regex
命名空间
boost::regex
请先安装好boost库, 添加boost的include 和 lib 路径.
例子 test.cpp
#include <boost/regex.hpp>
#include <iostream>
using namespace boost;
int main(int argc , const char ** argv)
{
if( argc != 2 )
{
std::cout<<"a.out string_your_need"<<std::endl;
return 0;
}
if(regex_match(argv[1],regex("Hello" , regex::extended )))
std::cout<<"Yes"<<std::endl;
else
std::cout<<"No"<<std::endl;
return 0;
}
编译命令
g++ -I boost_1_57_0/ -lboost_regex test.cpp
这样就生成了一个a.out , 执行后参数为Hello的话就输出Yes , 否则No

本文档介绍了如何使用 Boost.Regex 库进行正则表达式的匹配操作。首先需要安装 Boost 库并设置 include 和 lib 路径,然后通过示例代码展示了如何在 C++ 中使用 Boost.Regex 进行字符串匹配。

241

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



