This regex will trim the string at line breaks.
I want it to trim both end only and preserve any line breaks in the middle.
string s(" Stack \n Overflow ");
boost::regex expr("^[ \t]+|[ \t]+$");
std::string fmt("");
cout << boost::regex_replace(s, expr, fmt) << endl;
If you want to make the regular expression match at the beginning and the
end of the input string(want to preserve spaces around the in-between
\n),\Aand\zinstead of^and$might meet the purpose.For example: