std::regex_match 带有字符 é è à

std::regex_match with characters é è à

例如,我想将 "ram" 、 "rém" 、 "rèm" 和 "ràm" 视为有效输入,所以我这样做:

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

但在这种情况下 'valid' returns 错误,字符 é、è 和 à 有什么特别之处吗?我应该修改正则表达式吗? 谢谢

您可以使用 std::wstring 定义字符串,然后使用 std::wregex 在 Unicode 字符串上实际 运行 正则表达式:

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