Regex 头文件: "boost/regex
hpp" 正则表达式被封装为一个类型 basic_regex 的对象
我们将在下一节更深入地讨论正则表达式如何被编译和分析,这里我们首先粗略地看看 basic_regex ,以及这个库中三个最重要的算法
namespace boost { template class basic_regex { public: explicit basic_regex( const charT* p, flag_type f=regex_constants::normal); bool empty() const; unsigned mark_count() const; flag_type flags() const; }; typedef basic_regex regex; typedef basic_regex wregex; } 成员函数 explicit basic_regex ( const charT* p, flag_type f=regex_constants::normal); 这个构造函数接受一个包含正则表达式的字符序列,还有一个参数用于指定使用正则表达式时的选项,例如是否忽略大小写
如果 p 中的正则表达式无效,则抛出一个 bad_expression 或 regex_error 的异常
注意这两个异常其实是同一个东西;在写这本书之时,尚未改变当前使用的名字 bad_expression ,但下一个版本的Boost
Regex 将会使用 regex_error
bool empty() const; 这个成员函数是一个谓词,当 basic_regex 实例没有包含一个有效的正则表达式时返回 true ,即它被赋予一个空的字符序列时
unsigned mark_count() const; mark_count