2016-05-04 7 views
1

次のC++コードをVS2013 Update 4およびVS2015 Update 3で使用すると、小文字を区別せずにケースに一致するようにして発生を置き換えるために::: Windows(VS2013 Update 4、VS2015 Update 3)で構文フラグicaseを持つstd :: regex_replaceが文字範囲を使用して一致しない

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" 

文字の範囲が大文字と小文字を区別しない理由は何ですか? 2番目の試合が見つからず、交換されなかったのはなぜですか?

答えて

1

私はこれがVisual Studioのバグかもしれないと感じます。 [A]から角括弧を削除すると問題なく動作します。あなたはそれが2試合を見つけregex_search使用している場合は奇妙なこと

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

...

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";