Kyle Alons wrote:
std::string in("hello"); std::string exprStr("(.*)"); std::string replStr("goodbye$1");
boost::regex expr(exprStr); std::string out(boost::regex_replace(in, expr, replStr));
printf("%s", out.c_str());
In Boost 1.31, this outputs "goodbyehello".
In 1.32+, it outputs "goodbyehellogoodbye".
Is it a bug, a by-design breaking change, or? Thanks.
By design. The old behavior was buggy. By default, regex_replace substitutes globally, and your pattern matches the string in two places: first, it matches the whole string; second, it matches the empty sequence at the end. In perl: $str = 'hello'; $str =~ s/(.*)/goodbye$1/g; print "$str\n"; This prints "goodbyehellogoodbye". Have a look in the docs for regex_constants::format_first_only. HTH, -- Eric Niebler Boost Consulting www.boost-consulting.com