NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
[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 } } ```