[C/C++]_[使用boost库的正则匹配模块替换字符串]

2014-11-24 07:57:53 · 作者: · 浏览: 0
1.C/C++没有像 Java那样的正则标准库,其中一个替代方案是boost的 #include
2.boost的正则库比较难用,这里只是其中一个简单的使用例子。
-- boost库里的dll都是可以单独使用的。这里只用了 libboost_regex-mgw44-1_46_1.dll
[cpp]
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
printf("Hello, world\n");
std::string in("my is test !  ... ..'");
boost::regex e1("'");
std::string result = boost::regex_replace(in,e1,"\'", boost::match_default | boost::format_all);
std::cout << result << std::endl;
return 0;
}
输出
[plain]
$ test.exe
Hello, world
my is test !  ... ..'