Thursday, November 10, 2011

Using boost's replace_all_regex_copy


#include <iostream>
#include <string>
#include <algorithm>
#include "boost/algorithm/string/regex.hpp"

using namespace std;

int main(void) {
string orig_str="FUBAR";
boost::regex re("UBA");
std::string replacement="ooba";
string result = boost::algorithm::replace_all_regex_copy(
orig_str,re,replacement);
cout << result << endl;
return 0;
}

Yields:

FoobaR