当前位置:编程学习 > C/C++ >>

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

 
1.C/C++没有像Java那样的正则标准库,其中一个替代方案是boost的 #include <boost/regex.hpp>
2.boost的正则库比较难用,这里只是其中一个简单的使用例子。
-- boost库里的dll都是可以单独使用的。这里只用了 libboost_regex-mgw44-1_46_1.dll
[cpp] 
#include <stdio.h>  
#include <fstream>  
#include <sstream>  
#include <string>  
#include <iterator>  
#include <boost/regex.hpp>  
#include <fstream>  
#include <iostream>   
    
  
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 !  ... ..'  
 
补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,