Help with boost::regex trim
This regex will trim the string at line breaks.
I want it to trim开发者_Go百科 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
),
\A
and \z
instead of ^
and $
might meet the purpose.
For example:
boost::regex expr("\\A[ \t]+|[ \t]+\\z");
精彩评论