C ++ 11 regex_match与它必须的不匹配

时间:2013-07-26 14:36:06

标签: c++ regex visual-studio-2012 c++11

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?

2 个答案:

答案 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]"