企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## 概述 ## 实例 #### regex_match ``` #include <iostream> #include <string> #include <regex> int main() { std::string fname = "foo.txt"; std::regex txt_regex("[a-z]+\\.txt"); //是否匹配 if (std::regex_match(fname, txt_regex)) { std::cout << "true"; }else { std::cout << "false"; } } ``` ### regex_match 获取匹配值 ``` #include <iostream> #include <string> #include <regex> int main() { std::string fname = "foo.txt"; std::regex txt_regex("([a-z]+)\.txt"); std::smatch match; //是否匹配 if (std::regex_match(fname,match, txt_regex)) { std::cout << "true"; }else { std::cout << "false"; } std::cout << "szie="<< match.size()<<"\n"; if (match.size()==2) { std::cout << "0=" << match[0].str() << "\n"; // 0=foo.txt std::cout <<"1=" <<match[1].str()<<"\n"; // 1=foo } } ```