basic_regex クラス
更新 : 2007 年 11 月
正規表現をラップします。
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
要素の特徴 (traits) クラス。
解説
このテンプレート クラスは、正規表現を保持するオブジェクトを表します。適切な文字列引数と共に regex_match 関数、regex_search 関数、regex_replace 関数 の各テンプレート関数に渡すことによって、正規表現と一致するテキストを検索できます。TR1 ライブラリには、このテンプレート クラスを特定の型定義に特化させた 2 つのクラスが提供されています。char 型の要素に特化した regex Typedef と、wchar_t 型の要素に特化した wregex Typedef です。
テンプレートの引数 RXtraits は、このテンプレート クラスでサポートされている正規表現の構文に関連した各種の重要なプロパティを表します。こうした正規表現の特徴 (traits) を指定するクラスは、テンプレート クラス regex_traits クラス のオブジェクトと同じ外部インターフェイスを持っている必要があります。
一部の関数は、正規表現を定義するオペランド シーケンスを受け取ります。その場合、オペランド シーケンスは次のような方法で指定できます。
ptr : ptr (null ポインタ以外) で始まり、null で終わるシーケンスとして (char 型の Elem の場合は C 文字列など)。終端の要素は、value_type() の値であり、オペランド シーケンスには属しません。
ptr、count : ptr (null ポインタ以外) で始まる count 個の要素のシーケンスとして。
str : basic_string オブジェクト str によって指定されたシーケンスとして。
first、last : first と last の 2 つの反復子で区切られた範囲 [first, last) 内の要素のシーケンスとして。
right : basic_regex オブジェクト right として。
これらのメンバ関数は、RXtraits 型での定義に加え、正規表現の解釈に関連した各種オプションを指定する flags を引数として受け取ります。
必要条件
ヘッダー : <regex>
名前空間 : std::tr1