basic_regex Class

包装正则表达式。

template<class Elem,
    class RXtraits = regex_traits<Elem>,
    class basic_regex {
public:
    basic_regex();
    explicit basic_regex(const Elem *ptr,
        flag_type flags = ECMAScript);
    basic_regex(const Elem *ptr, size_type len,
        flag_type flags = ECMAScript);
    basic_regex(const basic_regex& right);
    template<class STtraits, class STalloc>
        explicit basic_regex(const basic_string<Elem, STtraits, STalloc>& str,
            flag_type flags = ECMAScript);
    template<class InIt>
        explicit basic_regex(InIt first, InIt last,
            flag_type flags = ECMAScript);

    basic_regex& operator=(const basic_regex& right);
    basic_regex& operator=(const Elem *ptr);
    template<class STtraits, class STalloc>
        basic_regex& operator=(const basic_string<Elem, STtraits, STalloc>& str);
    basic_regex& assign(const basic_regex& right);
    basic_regex& assign(const Elem *ptr,
        flag_type flags = ECMAScript);
    basic_regex& assign(const Elem *ptr, size_type len,
        flag_type flags = ECMAScript);
    template<class STtraits, class STalloc>
    basic_regex& assign(const basic_string<Elem, STtraits, STalloc>& str,
        flag_type flags = ECMAScript);
    template<class InIt>
        basic_regex& assign(InIt first, InIt last,
            flag_type flags = ECMAScript);

    locale_type imbue(locale_type loc);
    locale_type getloc() const;
    void swap(basic_regex& other) throw();
    unsigned mark_count() const;
    flag_type flags() const;

    typedef Elem value_type;
    typedef regex_constants::syntax_option_type flag_type;
    typedef typename RXtraits::locale_type locale_type;
    static const flag_type icase = regex_constants::icase;
    static const flag_type nosubs = regex_constants::nosubs;
    static const flag_type optimize = regex_constants::optimize;
    static const flag_type collate = regex_constants::collate;
    static const flag_type ECMAScript = regex_constants::ECMAScript;
    static const flag_type basic = regex_constants::basic;
    static const flag_type extended = regex_constants::extended;
    static const flag_type awk = regex_constants::awk;
    static const flag_type grep = regex_constants::grep;
    static const flag_type egrep = regex_constants::egrep;
private:
    RXtraits traits;    // exposition only
    };

参数

  • Elem
    元素的类型要匹配的。

  • RXtraits
    元素的特征的类。

备注

模板类描述存放一个正则表达式的对象。此模板类对象可传递到模板函数 regex_match Functionregex_search Functionregex_replace Function,用适当的文本字符串参数时,搜索与该正则表达式的文本。TR1 库提供此模板两个类的专用化,以类型定义 regex Typedef 为类型 char的元素和 wregex Typedef 为类型 wchar_t的元素。

模板参数 RXtraits 介绍正则表达式的语法的各种重要属性模板类支持。指定这些正则表达式特征的类必须有外部接口和模板类同名 regex_traits Class对象。

某些函数采用定义正则表达式的操作数序列。您可以通过此方式指定操作数顺序多种:

ptr --在的 null 终止的序列 (例如 c. 字符串, Elem 的类型 char) 开头不能为 null 指针) 的 ptr (,其中是停止的元素是值 value_type() 并不作为操作数序列的一部分

ptr, count -- count 元素序列开始在中不能为 null 指针) 的 ptr (

str -- basic_string 对象指定的顺序 str

first, last --在范围 [first, last)的迭代器分隔的元素序列 first 和 last,

right -- basic_regex 对象 right

这些成员函数也采用为正则表达式介绍指定各种选项除了 RXtraits 类型的描述之外的参数 flags 。

要求

**标题:**regex

命名空间: std

请参见

参考

<regex>

regex_match Function

regex_search Function

regex_replace Function

regex Typedef

wregex Typedef

regex_traits Class

其他资源

regex 成员