Boost logo

Boost Users :

From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2006-05-22 07:53:15


Hi,

I'd like to replace all parts of a string with the results of calling a
function, passing the match as a parameter. Some pseudo-code:

---
std::string replacer(smatch& s)
{
    return std::getenv(s[1].c_str());
}
std::string const input = "This is ${USER} on ${HOST}";
boost::regex const re("\\$\\{([^\\}]+)\\}");
std::string result = boost::regex_replace(input, re, 
boost::bind(&replacer));
assert("This is Me on MyWorkstation" == result);
---
(I'm sure there are errors above, but I hope you get the general idea).
Any easy way to do something similar?
// Johan

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net