1
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?

4

2 回答 2

5

修复您的代码如下:

std::string pattern = "disk[0-9]";
std::regex regex(pattern, std::regex::ECMAScript | std::regex::icase); //Ignore Case
于 2013-07-26T14:49:56.030 回答
4

根据评论,正确答案应该是(包括字母 D 的可变大小写):

pattern = "[Dd]isk[0-9]"
于 2013-07-26T14:47:57.150 回答