【发布时间】:2016-05-04 11:49:47
【问题描述】:
我将以下 C++ 代码与 VS2013 Update 4 和 VS2015 Update 3 一起使用,使用字符范围尝试不区分大小写地匹配并替换出现的位置:
std::wstring strSource(L"Hallo Welt, HALLO WELT");
std::wstring strReplace(L"ello");
std::regex_constants::syntax_option_type nReFlags =
std::regex::ECMAScript |
std::regex::optimize |
std::regex::icase;
std::wregex re(L"[A]LLO", nReFlags);
std::wstring strResult = std::regex_replace(strSource, re, strReplace);
wcout << L"Source: \"" << strSource.c_str() << L"\"" << endl
<< L"Result: \"" << strResult.c_str() << L"\"" << endl;
我期望的输出:
Source: "Hallo Welt, HALLO WELT"
Result: "Hello Welt, Hello WELT"
但我明白了:
Source: "Hallo Welt, HALLO WELT"
Result: "Hello Welt, HALLO WELT"
为什么没有应用字符范围不区分大小写? 为什么第二个匹配项似乎没有找到并被替换?
【问题讨论】:
标签: c++ regex visual-studio-2013 stl case-insensitive