std::string pattern = "[disk0-9]";
std::regex regex(pattern, std::regex::ECMAScript);
std::string subject = "Disk1";
bool result = std::regex_match(subject, regex, std::regex_constants::match_any);
std::cout << result << std::endl;
请问为什么regex_match
会返回false?
答案 0 :(得分:5)
修改您的代码如下:
std::string pattern = "disk[0-9]";
std::regex regex(pattern, std::regex::ECMAScript | std::regex::icase); //Ignore Case
答案 1 :(得分:4)
根据评论,正确答案应该是(包括字母D的变量大小写):
pattern = "[Dd]isk[0-9]"