我找到了替换Regex replace uppercase with lowercase letters的正则表达式
Find: (\w) Replace With: \L$1 我的代码
string s = "ABC";
cout << std::regex_replace(s, std::regex("(\\w)"), "\\L$1") << endl;在2017中运行。
产出:
\LA\LB\LC
如何用C++编写小写函数标记?
发布于 2018-11-02 06:33:28
由于没有像\L那样的魔力,我们必须妥协--使用regex_search并手动地将鞋帮隐藏到较低的位置。
template<typename ChrT>
void RegexReplaceToLower(std::basic_string<ChrT>& s, const std::basic_regex<ChrT>& reg)
{
using string = std::basic_string<ChrT>;
using const_string_it = string::const_iterator;
std::match_results<const_string_it> m;
std::basic_stringstream<ChrT> ss;
for (const_string_it searchBegin=s.begin(); std::regex_search(searchBegin, s.cend(), m, reg);)
{
for (int i = 0; i < m.length(); i++)
{
s[m.position() + i] += ('a' - 'A');
}
searchBegin += m.position() + m.length();
}
}
void _replaceToLowerTest()
{
string sOut = "I will NOT leave the U.S.";
RegexReplaceToLower(sOut, regex("[A-Z]{2,}"));
cout << sOut << endl;
}https://stackoverflow.com/questions/53112726
复制相似问题