C++标准库中正则表达式的使用
qianghaohao
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <regex>
using namespace std;
///
/// C++标准库中正则表达式的使用简介:
/// C++标准库中提供了对正表达式的支持,以下是常用的使用方法.
///
/// regex类:定义包含正则表达式的对象,如:regex rx("a(b?)c");
///
/// cmatch类:Type definition for char match_results.用来
/// 定义保存匹配结果的对象-->typedef match_results<const char*> cmatch;
/// 当待搜索的字符串是char类型是,使用此类对象
///
/// smatch类:Type definition for string match_results.用来
/// 定义保存匹配结果的对象-->typedef match_results<string::const_iterator> smatch;
/// 当待搜索的字符串是string类型是,使用此类对象
///
/// ==========================以下是三个常用的正则匹配函数==================================
/// *bool regex_match(...)函数:Exactly matches a regular expression,判断是否准确匹配 *
/// *Tests whether a regular expression matches the entire target string *
/// *是否准确匹配整个目标字符串 *
/// *注意:regex_match是目标字符串和正则表达式要完全匹配时才返回true. *
/// *如"abc"和"ab*c" 完全匹配,但是如果是"abcd"和"ab*c",虽然只有部分匹配(abc)但是返回是false*
/// * *
/// *bool regex_search(...)函数:Searches for