簡體   English   中英

C ++ 11 regex_match與它必須匹配的不匹配

[英]C++11 regex_match does not match what it must

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?

修改代碼如下:

std::string pattern = "disk[0-9]";
std::regex regex(pattern, std::regex::ECMAScript | std::regex::icase); //Ignore Case

根據評論,正確答案應為(包括字母D的可變大小寫):

pattern = "[Dd]isk[0-9]"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM