例如,我想将“ 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,字符é,è和à是否有特殊之处?我应该修改正则表达式吗?谢谢
您可以使用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