开发者

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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜