帮助 boost::regex 修剪
该正则表达式将在换行符处修剪字符串。
我希望它仅修剪两端并保留中间的任何换行符。
string s(" Stack \n Overflow ");
boost::regex expr("^[ \t]+|[ \t]+$");
std::string fmt("");
cout << boost::regex_replace(s, expr, fmt) << endl;
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;
如果你想让正则表达式匹配开头和后面
输入字符串的末尾(想要保留中间
\n
周围的空格),\A
和\z
而不是^
和$
可能会达到目的。例如:
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: