:: std :: regex_replace with icase syntax flag on Windows (VS2013 Update 4, VS2015 Update 3) does not match character ranges

I am using the following C ++ code with VS2013 Update 4 and VS2015 Update 3, using a range of characters to try case-insensitive and replace occurrences:

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;

I was expecting an exit:

Source: "Hallo Welt, HALLO WELT"
Result: "Hello Welt, Hello WELT"

But I get:

Source: "Hallo Welt, HALLO WELT"
Result: "Hello Welt, HALLO WELT"

Why did the character range not get caseinsensitive? Why didn't the second match seem to be found and replaced?

+1
source share
1 answer

I feel this may be a bug in Visual Studio. If you remove the brackets from [A], it works fine.

std::wregex  re(L"ALLO", nReFlags);

, regex_search, 2 ...

std::wregex  re(L"([A]LLO)", nReFlags);
std::wsmatch match;
std::regex_search(strSource, match, re);
for (auto i = 0; i < match.size(); ++i)
    std::wcout << match[i] << "\n";
+1

Source: https://habr.com/ru/post/1685296/


All Articles