1 安装
sudo apt-get install libboost-dev
2 使用
#include <iostream>
#include <string>
#include "boost/regex.hpp"
int main() {
boost::regex reg("(Colo)(u)(r)",
boost::regex::icase|boost::regex::perl);
std::string s="Colour, colours, color, colourize";
s=boost::regex_replace(s,reg,"$1$3");
std::cout << s;
}
把上面内容保存到re.cpp
文件中
编译:g++ -o re re.cpp -llibboost_regex
运行:./re
输出:Color, colors, color, colorize