std :: regex_match与字符éèà

问题描述 投票:2回答:1

例如,我想将“ ram”,“rém”,“rèm”和“ràm”视为有效输入,因此我这样做:

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

但是在这种情况下'valid'返回false,字符é,è和à是否有特殊之处?我应该修改正则表达式吗?谢谢

c++ regex c++11 visual-studio-2017 std
1个回答
1
投票

您可以使用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
© www.soinside.com 2019 - 2024. All rights reserved.