分别为regex_search 和 regex_replace
#include <iostream>
#include <boost/regex.hpp>
using namespace std;
void main()
{
// const char *szReg = "(.*?)(1)(.*)";
// const char *szStr = "ARIX11";
// boost::smatch mat;
// try
// {
// boost::regex reg( szReg );
// bool r=boost::regex_search( szStr, mat, reg);
// if(r)
// {
// cout << mat.size() << endl;
// for(size_t i = 0; i < mat.size(); ++i)
// {
//
// if (mat[i].matched)
// {
// std::cout << mat[i] << std::endl;
// std::string sTest = mat[i].second;
// }
// }
// }
// }
// catch (exception& e)
// {
// return;
// }
string s1 = "(.*?)(1)(.*)";
string s2 = "($1)2($3)";
boost::regex reg( s1 );
string s = boost::regex_replace( string("ARIX11"), reg, s2, boost::match_default|boost::format_all);
cout << s << endl;
char* a;
cin >> a;
}