Using Boost C++ library to do a regex replace with a custom replacement -
i can use xpressive of boost library regex replacement this:
#include <iostream> #include <boost/xpressive/xpressive.hpp> void replace(){ std::string in("a(bc) de(fg)"); sregex re = +_w >> '(' >> (s1= +_w) >> ')'; std::string out = regex_replace(in,re,"$1"); std::cout << out << std::endl; }
what need replace captured part result of transformation function e.g.
std::string modifystring(std::string &in){ std::string out(in); std::reverse(out.begin(),out.end()); return out; }
so result of example provided above cb gf.
what think best approach realize this?
thanks in advance!
use
std::string modifystring(const smatch& match){ std::string out(match[1]); std::reverse(out.begin(),out.end()); return out; } void replace(){ std::string in("a(bc) de(fg)"); sregex re = +_w >> '(' >> (s1= +_w) >> ')'; std::string out = regex_replace(in, re, modifystring); std::cout << out << std::endl; }
in documentation there regex_replace
function view desctiption/requires
Comments
Post a Comment