Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 标准::正则表达式搜索反向搜索_C++_Regex_String_Iterator_C++17 - Fatal编程技术网

C++ 标准::正则表达式搜索反向搜索

C++ 标准::正则表达式搜索反向搜索,c++,regex,string,iterator,c++17,C++,Regex,String,Iterator,C++17,您可以通过regex_搜索(s.cbegin(),s.cend()… string s = "abcde, eee12345 11111ddd 55555 hello"; std::smatch m; bool b = std::regex_search(s.cbegin(), s.cend(), m, std::regex("[0-9]{5}")); cout << m[0] << endl; 但它并没有编译错误 错误C2672

您可以通过
regex_搜索(s.cbegin(),s.cend()…

string s = "abcde, eee12345 11111ddd 55555 hello";
std::smatch m;
bool b = std::regex_search(s.cbegin(), s.cend(), m, std::regex("[0-9]{5}"));
cout << m[0] << endl;
但它并没有编译错误

错误C2672'std::regex_search':找不到与test匹配的重载函数

关于C++17标准的可视化研究。
为什么?

这是因为迭代器类型不匹配,如果您在Visual Studio中查看
std::smatch
的源代码,就会发现这一点

使用smatch=匹配结果;
您正试图在
std::regex\u search
调用中传递
std::string::const\u reverse\u迭代器

直接使用
std::match_结果

const std::string s=“abcde,eee12345 11111 ddd 55555 hello”;
std::匹配结果m;
bool b=std::regex_搜索(s.crbegin(),s.crend(),m,std::regex(“[0-9]{5}”);

std::cout作为旁注,您应该尝试不同的实现,然后
std::regex
,这在性能方面还有很多需要改进的地方
std::regex_search(s.crbegin(), s.crend(), m, std::regex("[0-9]{5}"));