boost正则简单字符串替换笔记

来源:互联网 发布:淘宝卖家怎么延长收货 编辑:程序博客网 时间:2024/06/11 08:07

头文件

#ifndef REGEXUTIL_H#define REGEXUTIL_H#include <iostream>#include <boost/xpressive/xpressive.hpp>#include"string"using namespace std;using namespace boost::xpressive;class RegexUtil {public:    RegexUtil();    virtual ~RegexUtil();    void removeSurplusSpace(string&);    void replaceSlash(string&,string&);protected:private:};#endif // REGEXUTIL_H

源文件:

#include "RegexUtil.h"RegexUtil::RegexUtil() {    //ctor}RegexUtil::~RegexUtil() {    //dtor}void RegexUtil::removeSurplusSpace(string& text) {    sregex rex = sregex::compile( " +" );    text=regex_replace(text, rex, " " );}void RegexUtil::replaceSlash(string& text,string& newString){    sregex rex = sregex::compile( "/+" );    text=regex_replace(text, rex, newString);}


0 0