Search code examples
c++regexc++11visual-studio-2017std

std::regex_match with characters é è à


I want for example to consider "ram" , "rém" , "rèm" and "ràm" as a valid input, so i do this:

std::string ss = "rém";
bool valid = std::regex_match(ss, std::regex("r[aéèà]m"));

but in this case 'valid' returns false, is there something special with the characters é, è and à ? Should i modify the regex expression ? Thanks


Solution

  • You may make use of std::wstring to define the string and then use std::wregex to actually run regex on Unicode strings:

    std::wstring ss = L"rém";
    std::wcout << std::regex_match(ss, std::wregex(L"r[aéèà]m"));
    // => 1, there is a match