帮助提升::正则表达式修剪

Help with boost::regex trim

本文关键字:正则表达式 修剪 帮助      更新时间:2023-10-16

此正则表达式将在换行符处修剪字符串。
我希望它修剪两端并保留中间的任何换行符。

string s("     Stack n Overflow    ");
boost::regex expr("^[ t]+|[ t]+$");
std::string fmt("");
cout << boost::regex_replace(s, expr, fmt) << endl;

如果要使正则表达式在开头和输入字符串的末尾(希望在中间n周围保留空格), Az而不是^$可能符合目的。
例如:

boost::regex expr("\A[ t]+|[ t]+\z");