Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2004-11-11 08:44:47


> I have to use this replacement in my own string class which is inherited
> from
> std::string. I try it and it seems, that I have some trouble with the
> understanding of regex_iterator, also the existing examples doesn't help
> me :-(
> Is it possible for you, to look at my example and give me some hint, how
> to
> implement this case, with the regex_iterator?

std::string replace_with_literal(const std::string& text, const
boost::regex& re, const std::string& replace)
{
std::string result;
sregex_iterator it(text.begin(), text.end(), re);
sregex_iterator end;
std::string::const_iterator last_end = text.begin();
while(it != end)
{
result.append(it->prefix().str());
result.append(replace);
last_end = it->suffix().first;
}
result.append(last_end, text.end());
return result;
}

John.


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