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 } } ```