<regex>

Description
Synopsis
Classes
Template functions
Types
Operators

Description

Include the TR1 header <regex> to define a template class to parse regular expressions and several template classes and functions to search text for matches to a regular expression object.

Note:
To enable this header file, you must define the macro __IBMCPP_TR1__ .

To create a regular expression object use the template class basic_regex or one of its specializations, regex and wregex, along with the syntax flags of type syntax_option_type.

To search text for matches to a regular expression object use the template functions regex_match and regex_search, along with the match flags of type match_flag_type. These functions return their results using the template class match_results and its specializations, cmatch, wcmatch, smatch, and wsmatch, along with the template class sub_match and its specializations, csub_match, wcsub_match, ssub_match, and wssub_match.

To replace text that matches a regular expression object use the template function regex_replace, along with the match flags of type match_flag_type.

To iterate through multiple matches of a regular expression object use the template classes regex_iterator and regex_token_iterator or one of their specializations, cregex_iterator, sregex_iterator, wcregex_iterator, wsregex_iterator, cregex_token_iterator, sregex_token_iterator, wcregex_token_iterator, and wsregex_token_iterator, along with the match flags of type match_flag_type.

To modify some of the details of the grammar of regular expressions write a class that implements the regular expression traits.

Synopsis

namespace std {
    namespace tr1 {

 // TEMPLATE CLASS regex_traits AND basic_regex
 template<class Elem>
    struct regex_traits;
 template<>
    struct regex_traits<char>;
 template<>
    struct regex_traits<wchar_t>;
 template<class Elem,
    class RXtraits = regex_traits<Elem>,
    class basic_regex;
 typedef basic_regex<char> regex;
 typedef basic_regex<wchar_t> wregex;

 // TEMPLATE CLASS sub_match
 template<class BidIt>
    class sub_match;
 typedef sub_match<const char*> csub_match;
 typedef sub_match<const wchar_t*> wcsub_match;
 typedef sub_match<string::const_iterator> ssub_match;
 typedef sub_match<wstring::const_iterator> wssub_match;

 // TEMPLATE CLASS match_results
 template<class BidIt,
    class Alloc = allocator<typename iterator_traits<BidIt>::value_type> >
    class match_results;
 typedef match_results<const char*> cmatch;
 typedef match_results<const wchar_t*> wcmatch;
 typedef match_results<string::const_iterator> smatch;
 typedef match_results<wstring::const_iterator> wsmatch;

  // NAMESPACE regex_constants
        namespace regex_constants {
  typedef T1 syntax_option_type;
  static const syntax_option_type awk, basic, collate, ECMAScript,
    egrep, extended, grep, icase, nosubs, optimize;
  typedef T2 match_flag_type;
  static const match_flag_type match_any, match_default, match_not_bol,
    match_not_bow, match_continuous, match_not_eol, match_not_eow,
    match_not_null, match_partial, match_prev_avail;
  typedef T3 error_type;
  static const error_type error_badbrace, error_badrepeat, error_brace,
    error_brack, error_collate, error_complexity, error_ctype,
    error_escape, error_paren, error_range, error_space,
    error_stack, error_backref;
        }  // namespace regex_constants

 // CLASS regex_error
 class regex_error;

 // TEMPLATE FUNCTION regex_match
 template<class BidIt, class Alloc, class Elem, class RXtraits>
    bool regex_match(BidIt first, Bidit last,
        match_results<BidIt, Alloc>& match,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);
 template<class BidIt, class Elem, class RXtraits>
    bool regex_match(BidIt first, Bidit last,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);

 template<class Elem, class Alloc, class RXtraits>
    bool regex_match(const Elem* ptr,
        match_results<const Elem*, Alloc>& match,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);
 template<class Elem, class RXtraits>
    bool regex_match(const Elem* ptr,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);

 template<class IOtraits, class IOalloc, class Alloc, class Elem, class RXtraits>
    bool regex_match(
        const basic_string<Elem, IOtraits, IOalloc>& str,
        match_results<typename basic_string<Elem, IOtraits, IOalloc>::
        const_iterator, Alloc>& match,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags= match_default);
 template<class IOtraits, class IOalloc, class Elem, class RXtraits>
    bool regex_match(
        const basic_string<Elem, IOtraits, IOalloc>& match,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);

 // TEMPLATE FUNCTION regex_search
 template<class BidIt, class Alloc, class Elem, class RXtraits>
    bool regex_search(BidIt first, Bidit last,
        match_results<BidIt, Alloc>& match,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);
 template<class BidIt, class Elem, class RXtraits>
    bool regex_search(BidIt first, Bidit last,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);

 template<class Elem, class Alloc, class RXtraits>
    bool regex_search(const Elem* ptr,
        match_results<const Elem*, Alloc>& match,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);
 template<class Elem, class RXtraits>
    bool regex_search(const Elem* ptr,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);

 template<class IOtraits, class IOalloc, class Alloc, class Elem, class RXtraits>
    bool regex_search(
        const basic_string<Elem, IOtraits, IOalloc>& str,
        match_results<typename basic_string<Elem, IOtraits, IOalloc>::
        const_iterator, Alloc>& match,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);
 template<class IOtraits, class IOalloc, class Elem, class RXtraits>
    bool regex_search(
        const basic_string<Elem, IOtraits, IOalloc>& str,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);

 // TEMPLATE FUNCTION regex_replace
 template<class OutIt, class BidIt, class RXtraits, class Elem>
    OutIt regex_replace(OutIt out, BidIt first, BidIt last,
        const basic_regex<Elem, RXtraits>& re,
        const basic_string<Elem>& fmt,
        match_flag_type flags = match_default);
 template<class RXtraits, class Elem>
    basic_string<Elem> regex_replace(
        const basic_string<Elem>& str,
        const basic_regex<Elem, RXtraits>& re,
        const basic_string<Elem>& fmt,
        match_flag_type flags = match_default);

 // REGULAR EXPRESSION ITERATORS
 template<class BidIt, class Elem = iterator_traits<BidIt>::value_type,
    class RXtraits = regex_traits<Elem> >
        class regex_iterator;
 typedef regex_iterator<const char*> cregex_iterator;
 typedef regex_iterator<const wchar_t*> wcregex_iterator;
 typedef regex_iterator<string::const_iterator> sregex_iterator;
 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;

 template<class BidIt, class Elem = iterator_traits<BidIt>::value_type,
    class RXtraits = regex_traits<Elem> >
        class regex_token_iterator;
 typedef regex_token_iterator<const char*> cregex_token_iterator;
 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;

 // STREAM INSERTER
 template<class Elem, class IOtraits, class Alloc, class BidIt>
    basic_ostream<Elem, IOtraits>&
    operator<<(
        basic_ostream<Elem, IOtraits>& os,
        const sub_match<BidIt>& submatch);

 // TEMPLATE swap FUNCTIONS
 template<class Elem, class RXtraits>
    void swap(
        basic_regex<Elem, RXtraits>& left,
        basic_regex<Elem, RXtraits>& right) throw();
 template<class Elem, class IOtraits, class BidIt, class Alloc>
    void swap(
        match_results<BidIt, Alloc>& left,
        match_results<BidIt, Alloc>& right) throw();

 // COMPARISON OPERATORS FOR match_results
 template<class BidIt, class Alloc>
    bool operator==(
        const match_results<BidIt, Alloc>& left,
        const match_results<BidIt, Alloc>& right);
 template<class BidIt, class Alloc>
    bool operator!=(
        const match_results<BidIt, Alloc>& left,
        const match_results<BidIt, Alloc>& right);

 // COMPARISON OPERATORS FOR sub_match
 template<class BidIt>
    bool operator==(
        const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator!=(
        const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator<(
        const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator<=(
        const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator>(
        const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator>=(
        const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);

 template<class BidIt, class IOtraits, class Alloc>
    bool operator==(
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& left, const sub_match<BidIt>& right);
 template<class BidIt, class IOtraits, class Alloc>
    bool operator!=(
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& left, const sub_match<BidIt>& right);
 template<class BidIt, class IOtraits, class Alloc>
    bool operator<(
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& left, const sub_match<BidIt>& right);
 template<class BidIt, class IOtraits, class Alloc>
    bool operator<=(
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& left, const sub_match<BidIt>& right);
 template<class BidIt, class IOtraits, class Alloc>
    bool operator>(
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& left, const sub_match<BidIt>& right);
 template<class BidIt, class IOtraits, class Alloc>
    bool operator>=(
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& left, const sub_match<BidIt>& right);

 template<class BidIt, class IOtraits, class Alloc>
    bool operator==(
        const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& right);
 template<class BidIt, class IOtraits, class Alloc>
    bool operator!=(
        const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& right);
 template<class BidIt, class IOtraits, class Alloc>
    bool operator<(
        const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& right);
 template<class BidIt, class IOtraits, class Alloc>
    bool operator<=(
        const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& right);
 template<class BidIt, class IOtraits, class Alloc>
    bool operator>(
        const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type,
        IOtraits, Alloc>& right);
 template<class BidIt, class IOtraits, class Alloc>
    bool operator>=(
        const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& right);

 template<class BidIt>
    bool operator==(
        const typename iterator_traits<BidIt>::value_type* left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator!=(
        const typename iterator_traits<BidIt>::value_type* left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator<(
        const typename iterator_traits<BidIt>::value_type* left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator<=(
        const typename iterator_traits<BidIt>::value_type* left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator>(
        const typename iterator_traits<BidIt>::value_type* left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator>=(
        const typename iterator_traits<BidIt>::value_type* left,
        const sub_match<BidIt>& right);

 template<class BidIt>
    bool operator==(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type*);
 template<class BidIt>
    bool operator!=(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type*);
 template<class BidIt>
    bool operator<(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type*);
 template<class BidIt>
    bool operator<=(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type*);
 template<class BidIt>
    bool operator>(
        const sub_match<BidIt>&, left
        const typename iterator_traits<BidIt>::value_type*);
 template<class BidIt>
    bool operator>=(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type*);

 template<class BidIt>
    bool operator==(
        const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator!=(
        const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator<(
        const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator<=(
        const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator>(
        const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);
 template<class BidIt>
    bool operator>=(
        const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);

 template<class BidIt>
    bool operator==(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);
 template<class BidIt>
    bool operator!=(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);
 template<class BidIt>
    bool operator<(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);
 template<class BidIt>
    bool operator<=(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);
 template<class BidIt>
    bool operator>(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);
 template<class BidIt>
    bool operator>=(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);
    }  // namespace tr1
}  // namespace std

Classes

basic_regex
match_results
regex_error
regex_iterator
regex_token_iterator
regex_traits
regex_traits<char>
regex_traits<wchar_t>
sub_match

basic_regex

Description
Synopsis
Constructor
basic_regex::basic_regex
Types
basic_regex::flag_type
basic_regex::locale_type
basic_regex::value_type
Member functions
basic_regex::assign
basic_regex::flags
basic_regex::getloc
basic_regex::imbue
basic_regex::mark_count
basic_regex::swap
Constants
basic_regex::awk
basic_regex::basic
basic_regex::collate
basic_regex::ECMAScript
basic_regex::egrep
basic_regex::extended
basic_regex::grep
basic_regex::icase
basic_regex::nosubs
basic_regex::optimize
Operators
basic_regex::operator=
Description

The template class describes an object that holds a regular expression. Objects of this template class can be passed to the template functions regex_match, regex_search, and regex_replace, along with suitable text string arguments, to search for text that matches the regular expression. The TR1 library provides two specializations of this template class, with the type definitions regex for elements of type char, and wregex for elements of type wchar_t.

The template argument RXtraits describes various important properties of the syntax of the regular expressions that the template class supports. A class that specifies these regular expression traits must have the same external interface as an object of template class regex_traits.

Some functions take an operand sequence that defines a regular expression. You can specify such an operand sequence several ways:

These member functions also take an argument flags that specifies various options for the interpretation of the regular expression in addition to those described by the RXtraits type.

Synopsis
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
    };
Constructor
basic_regex::basic_regex

basic_regex();
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);
explicit basic_regex(const Elem *ptr,
    flag_type flags = ECMAScript);
explicit basic_regex(const Elem *ptr, size_type len,
    flag_type flags);
basic_regex(const basic_regex& right);

All constructors store a default-constructed object of type RXtraits.

The first constructor constructs an empty basic_regex object. The other constructors construct a basic_regex object that holds the regular expression described by the operand sequence.

An empty basic_regex object does not match any character sequence when passed to regex_match, regex_search, or regex_replace.

Types
basic_regex::flag_type

typedef regex_constants::syntax_option_type flag_type;

The type is a synonym for regex_constants::syntax_option_type.

basic_regex::locale_type

typedef typename RXtraits::locale_type locale_type;

The type is a synonym for regex_traits::locale_type.

basic_regex::value_type

typedef Elem value_type;

The type is a synonym for the template parameter Elem.

Member functions
basic_regex::assign

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);

The member functions each replace the regular expression held by *this with the regular expression described by the operand sequence, then return *this.

basic_regex::flags

flag_type flags() const;

The member function returns the value of the flag_type argument passed to the most recent call to one of the assign member functions or, if no such call has been made, the value passed to the constructor.

basic_regex::getloc

locale_type getloc() const;

The member function returns traits.getloc().

basic_regex::imbue

locale_type imbue(locale_type loc);

The member function empties *this and returns traits.imbue(loc).

basic_regex::mark_count

unsigned mark_count() const;

The member function returns the number of capture groups in the regular expression.

basic_regex::swap

void swap(basic_regex& right) throw();

The member function swaps the regular expressions between *this and right. It does so in constant time and throws no exceptions.

Constants
basic_regex::awk

static const flag_type awk = regex_constants::awk;

The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::awk.

basic_regex::basic

static const flag_type basic = regex_constants::basic;

The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::basic.

basic_regex::collate

static const flag_type collate = regex_constants::collate;

The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::collate.

basic_regex::ECMAScript

static const flag_type ECMAScript = regex_constants::ECMAScript;

The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::ECMAScript.

basic_regex::egrep

static const flag_type egrep = regex_constants::egrep;

The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::egrep.

basic_regex::extended

static const flag_type extended = regex_constants::extended;

The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::extended.

basic_regex::grep

static const flag_type grep = regex_constants::grep;

The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::grep.

basic_regex::icase

static const flag_type icase = regex_constants::icase;

The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::icase.

basic_regex::nosubs

static const flag_type nosubs = regex_constants::nosubs;

The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::nosubs.

basic_regex::optimize

static const flag_type optimize = regex_constants::optimize;

The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::optimize.

Operators
basic_regex::operator=

basic_regex& operator=(const basic_regex& right);
basic_regex& operator=(const Elem *str);
template<class STtraits, class STalloc>
basic_regex& operator=(const basic_string<Elem, STtraits, STalloc>& str);

The operators each replace the regular expression held by *this with the regular expression described by the operand sequence, then return *this.

match_results

Description
Synopsis
Constructor
match_results::match_results
Types
match_results::allocator_type
match_results::char_type
match_results::const_iterator
match_results::const_reference
match_results::difference_type
match_results::iterator
match_results::reference
match_results::size_type
match_results::string_type
match_results::value_type
Member functions
match_results::begin
match_results::empty
match_results::end
match_results::format
match_results::get_allocator
match_results::length
match_results::max_size
match_results::operator[]
match_results::position
match_results::prefix
match_results::size
match_results::str
match_results::suffix
match_results::swap
Operators
match_results::operator=
Description

The template class describes an object that controls a non-modifiable sequence of elements of type sub_match<BidIt> generated by a regular expression search. Each element points to the subsequence that matched the capture group corresponding to that element.

Synopsis
template<class BidIt,
    class Alloc = allocator<typename iterator_traits<BidIt>::value_type> >
    class match_results {
public:
    explicit match_results(const Alloc& alloc = Alloc());
    match_results(const match_results& right);

    match_results& operator=(const match_results& right);

    difference_type position(size_type sub = 0) const;
    difference_type length(size_type sub = 0) const;
    string_type str(size_type sub = 0) const;
    const_reference operator[](size_type n) const;

    const_reference prefix() const;
    const_reference suffix() const;
    const_iterator begin() const;
    const_iterator end() const;

    template<class OutIt>
        OutIt format(OutIt out,
            const string_type& fmt, 
            match_flag_type flags = format_default) const;
    string_type format(const string_type& fmt,
        match_flag_type flags = format_default) const;

    allocator_type get_allocator() const;
    void swap(const match_results& other) throw();

    size_type size() const;
    size_type max_size() const;
    bool empty() const;

    typedef sub_match<BidIt> value_type;
    typedef const typename Alloc::const_reference const_reference;
    typedef const_reference reference;
    typedef T0 const_iterator;
    typedef const_iterator iterator;
    typedef typename iterator_traits<BidIt>::difference_type difference_type;
    typedef typename Alloc::size_type size_type;
    typedef Alloc allocator_type;
    typedef typename iterator_traits<BidIt>::value_type char_type;
    typedef basic_string<char_type> string_type;
    };
Constructor
match_results::match_results

explicit match_results(const Alloc& alloc = Alloc());
match_results(const match_results& right);

The first constructor constructs a match_results object that holds no submatches. The second constructor constructs a match_results object that is a copy of right.

Types
match_results::allocator_type

typedef Alloc allocator_type;

The typedef is a synonym for the template argument Alloc.

match_results::char_type

typedef typename iterator_traits<BidIt>::value_type char_type;

The typedef is a synonym for the type iterator_traits<BidIt>::value_type, which is the element type of the character sequence that was searched.

match_results::const_iterator

typedef T0 const_iterator;

The typedef describes an object that can server as a constant random-access iterator for the controlled sequence.

match_results::const_reference

typedef const typename Alloc::const_reference const_reference;

The typedef describes an object that can serve as a constant reference to an element of the controlled sequence.

match_results::difference_type

typedef typename iterator_traits<BidIt>::difference_type difference_type;

The typedef is a synonym for the type iterator_traits<BidIt>::difference_type; it describes an object that can represent the difference between any two iterators that point at elements of the controlled sequence.

match_results::iterator

typedef const_iterator iterator;

The type describes an object that can serve as a random-access iterator for the controlled sequence.

match_results::reference

typedef const_reference reference;

The type is a synonym for the type const_reference.

match_results::size_type

typedef typename Alloc::size_type size_type;

The type is a synonym for the type Alloc::size_type.

match_results::string_type

typedef basic_string<char_type> string_type;

The type is a synonym for the type basic_string<char_type>.

match_results::value_type

typedef sub_match<BidIt> value_type;

The typedef is a synonym for the type sub_match<BidIt>.

Member functions
match_results::begin

const_iterator begin() const;

The member function returns a random access iterator that points at the first element of the sequence (or just beyond the end of an empty sequence).

match_results::empty

bool empty() const;

The member function returns true only if the regular expression search failed.

match_results::end

const_iterator end() const;

The member function returns an iterator that points just beyond the end of the sequence.

match_results::format

template<class OutIt>
    OutIt format(OutIt out,
        const string_type& fmt, 
        match_flag_type flags = format_default) const;

string_type format(const string_type& fmt,
    match_flag_type flags = format_default) const;

Each member function generates formatted text under the control of the format fmt. The first member function writes the formatted text to the sequence defined by its argument out and returns out. The second member function returns a string object holding a copy of the formatted text.

To generate formatted text literal text in the format string is ordinarily copied to the target sequence. Each escape sequence in the format string is replaced by the text that it represents. The details of the copying and replacement are controlled by the format flags passed to the function.

match_results::get_allocator

allocator_type get_allocator() const;

The member function returns a copy of the allocator object used by *this to allocate its sub_match objects.

match_results::length

difference_type length(size_type sub = 0) const;

The member function returns (*this)[sub].length().

match_results::max_size

size_type max_size() const;

The member function returns the length of the longest sequence that the object can control.

match_results::operator[]

const_reference operator[](size_type n) const;

The member function returns a reference to element n of the controlled sequence, or a reference to an empty sub_match object if size() <= n or if the capture group n was not part of the match.

match_results::position

difference_type position(size_type sub = 0) const;

The member function returns std::distance(prefix().first, (*this)[sub].first), that is, the distance from the first character in the target sequence to the first character in the submatch pointed to by element n of the controlled sequence.

match_results::prefix

const_reference prefix() const;

The member function returns a reference to an object of type sub_match<BidIt> that points to the character sequence that begins at the start of the target sequence and ends at (*this)[0].first, that is, it points to the text that precedes the matched subsequence.

match_results::size

size_type size() const;

The member function returns one more than the number of capture groups in the regular expression that was used for the search, or 0 if no search has been made.

match_results::str

string_type str(size_type sub = 0) const;

The member function returns string_type((*this)[sub]).

match_results::suffix

const_reference suffix() const;

The member function returns a reference to an object of type sub_match<BidIt> that points to the character sequence that begins at (*this)[size() - 1].second and ends at the end of the target sequence, that is, it points to the text that follows the matched subsequence.

match_results::swap

void swap(const match_results& right) throw();

The member function swaps the contents of *this and right in constant time and does not throw exceptions.

Operators
match_results::operator=

match_results& operator=(const match_results& right);

The member operator replaces the sequence controlled by *this with a copy of the sequence controlled by right.

regex_error

Description
Synopsis
Constructor
regex_error::regex_error
Member functions
regex_error::code
Description

The class describes an exception object thrown to report an error in the construction or use of a basic_regex object.

Synopsis
class regex_error : public std::runtime_error {
public:
    explicit regex_error(regex_constants::error_code error);
    regex_constants::error_code code() const;
    };
Constructor
regex_error::regex_error

regex_error(regex_constants::error_code error);

The constructor constructs an object that holds the value error.

Member functions
regex_error::code

regex_constants::error_code code() const;

The member function returns the value that was passed to the object's constructor.

regex_iterator

Description
Synopsis
Constructor
regex_iterator::regex_iterator
Types
regex_iterator::difference_type
regex_iterator::iterator_category
regex_iterator::pointer
regex_iterator::reference
regex_iterator::regex_type
regex_iterator::value_type
Member functions
regex_iterator::operator==
regex_iterator::operator!=
regex_iterator::operator*
regex_iterator::operator->
Operators
regex_iterator::operator++
Description

The template class describes a constant forward iterator object. It extracts objects of type match_results<BidIt> by repeatedly applying its regular expression object *pregex to the character sequence defined by the iterator range [begin,end).

Synopsis
template<class BidIt, class Elem = iterator_traits<BidIt>::value_type,
    class RXtraits = regex_traits<Elem> >
        class regex_iterator {
public:
    typedef basic_regex<Elem, RXtraits> regex_type;
    typedef match_results<BidIt> value_type;
    typedef std::forward_iterator_tag iterator_category;
    typedef std::ptrdiff_t difference_type;
    typedef const match_results<BidIt>* pointer;
    typedef const match_results<BidIt>& reference;

    regex_iterator();
    regex_iterator(BidIt first, BidIt last, const regex_type& re,
			regex_constants::match_flag_type f = regex_constants::match_default);

    bool operator==(const regex_iterator& right);
    bool operator!=(const regex_iterator& right);

    const match_results<BidIt>& operator*();
    const match_results<BidIt> *operator->();
    regex_iterator& operator++();
    regex_iterator& operator++(int);

    BidIt begin;                            // exposition only
    BidIt end;                              // exposition only
    regex_type *pregex;                     // exposition only
    regex_constants::match_flag_type flags; // exposition only
    match_results<BidIt> match;             // exposition only
    };
Constructor
regex_iterator::regex_iterator

regex_iterator();
regex_iterator(BidIt first, BidIt last,
    const regex_type& re, 
    regex_constants::match_flag_type f = regex_constants::match_default);

The first constructor constructs an end-of-sequence iterator. The second constructor initializes the stored value begin with first, the stored value end with last, the stored value pregex with &re, and the stored value flags with f. It then calls regex_search(begin, end, match, *pregex, flags). If the search fails, the constructor sets the object to an end-of-sequence iterator.

Types
regex_iterator::difference_type
regex_iterator::iterator_category
regex_iterator::pointer
regex_iterator::reference
regex_iterator::regex_type
regex_iterator::value_type
regex_iterator::difference_type

typedef std::ptrdiff_t difference_type;

The type is a synonym for std::ptrdiff_t.

regex_iterator::iterator_category

typedef std::forward_iterator_tag iterator_category;

The type is a synonym for std::forward_iterator_tag.

regex_iterator::pointer

typedef match_results<BidIt> *pointer;

The type is a synonym for match_results<BidIt>*, where BidIt is the template parameter.

regex_iterator::reference

typedef match_results<BidIt>& reference;

The type is a synonym for match_results<BidIt>&, where BidIt is the template parameter.

regex_iterator::regex_type

typedef basic_regex<Elem, RXtraits> regex_type;

The typedef is a synonym for basic_regex<Elem, RXtraits>.

regex_iterator::value_type

typedef match_results<BidIt> value_type;

The type is a synonym for match_results<BidIt>, where BidIt is the template parameter.

Member functions
regex_iterator::operator==

bool operator==(const regex_iterator& right);

The member function returns true if *this and right are both end-of-sequence iterators or if neither is an end-of-sequence iterator and begin == right.begin, end == right.end, pregex == right.pregex, and flags == right.flags. Otherwise it returns false.

regex_iterator::operator!=

bool operator!=(const regex_iterator& right);

The member function returns !(*this == right).

regex_iterator::operator*

const match_results<BidIt>& operator*();

The member function returns the stored value match.

regex_iterator::operator->

const match_results<BidIt> *operator->();

The member function returns the address of the stored value match.

Operators
regex_iterator::operator++

regex_iterator& operator++();
regex_iterator& operator++(int);

If the current match has no characters the first operator calls regex_search(begin, end, match, *pregex, flags | regex_constants::match_prev_avail | regex_constants::match_not_null); otherwise it advances the stored value begin to point to the first character after the current match then calls regex_search(begin, end, match, *pregex, flags | regex_constants::match_prev_avail). In either case, if the search fails the operator sets the object to an end-of-sequence iterator. The operator returns the object.

The second operator makes a copy of the object, increments the object, then returns the copy.

regex_token_iterator

Description
Synopsis
Constructor
regex_token_iterator::regex_token_iterator
Types
regex_token_iterator::difference_type
regex_token_iterator::iterator_category
regex_token_iterator::pointer
regex_token_iterator::reference
regex_token_iterator::regex_type
regex_token_iterator::value_type
Member functions
regex_token_iterator::operator==
regex_token_iterator::operator!=
regex_token_iterator::operator*
regex_token_iterator::operator->
Operators
regex_token_iterator::operator++
Description

The template class describes a constant forward iterator object. Conceptually, it holds a regex_iterator object that it uses to search for regular expression matches in a character sequence. It extracts objects of type sub_match<BidIt> representing the submatches identified by the index values in the stored vector subs for each regular expression match.

An index value of -1 designates the character sequence beginning immediately after the end of the previous regular expression match, or beginning at the start of the character sequence if there was no previous regular expression match, and extending to but not including the first character of the current regular expression match, or to the end of the character sequence if there is no current match. Any other index value idx designates the contents of the capture group held in it.match[idx].

Synopsis
template<class BidIt, class Elem = iterator_traits<BidIt>::value_type,
    class RXtraits = regex_traits<Elem> >
        class regex_token_iterator {
public:
    typedef basic_regex<Elem, RXtraits> regex_type;
    typedef sub_match<BidIt> value_type;
    typedef std::forward_iterator_tag iterator_category;
    typedef std::ptrdiff_t difference_type;
    typedef const sub_match<BidIt> *pointer;
    typedef const sub_match<BidIt>& reference;

    regex_token_iterator();
    regex_token_iterator(BidIt first, BidIt last,
        const regex_type& re, int submatch = 0,
        regex_constants::match_flag_type f = regex_constants::match_default);
    regex_token_iterator(BidIt first, BidIt last,
        const regex_type& re, const std::vector<int> submatches,
        regex_constants::match_flag_type f = regex_constants::match_default);
    template<std::size_t N>
    regex_token_iterator(BidIt first, BidIt last,
        const regex_type& re, const int (&submatches)[N],
        regex_constants::match_flag_type f = regex_constants::match_default);

    bool operator==(const regex_token_iterator& right);
    bool operator!=(const regex_token_iterator& right);

    const basic_string<Elem>& operator*();
    const basic_string<Elem> *operator->();
    regex_token_iterator& operator++();
    regex_token_iterator& operator++(int);

private:
    regex_iterator<BidIt, Elem, RXtraits> it; // exposition only
    vector<int> subs;                         // exposition only
    int pos;                                  // exposition only
    };
Constructor
regex_token_iterator::regex_token_iterator

regex_token_iterator();
regex_token_iterator(BidIt first, BidIt last,
    const regex_type& re, int submatch = 0,
    regex_constants::match_flag_type f = regex_constants::match_default);
regex_token_iterator(BidIt first, BidIt last,
    const regex_type& re, const vector<int> submatches,
    regex_constants::match_flag_type f = regex_constants::match_default);
template<std::size_t N>
regex_token_iterator(BidIt first, BidIt last,
    const regex_type& re, const int (&submatches)[N],
    regex_constants::match_flag_type f = regex_constants::match_default);

The first constructor constructs an end-of-sequence iterator.

The second constructor constructs an object whose stored iterator it is initialized to regex_iterator<BidIt, Elem, RXtraits<(first, last, re, f), whose stored vector subs holds exactly one integer, with value submatch, and whose stored value pos is 0. Note: the resulting object extracts the submatch identified by the index value submatch for each successful regular expression match.

The third constructor constructs an object whose stored iterator it is initialized to regex_iterator<BidIt, Elem, RXtraits<(first, last, re, f), whose stored vector subs holds a copy of the constructor argument submatches, and whose stored value pos is 0.

The fourth constructor constructs an object whose stored iterator it is initialized to regex_iterator<BidIt, Elem, RXtraits<(first, last, re, f), whose stored vector subs holds the N values pointed to by the constructor argument submatches, and whose stored value pos is 0.

Types
regex_token_iterator::difference_type

typedef std::ptrdiff_t difference_type;

The type is a synonym for std::ptrdiff_t.

regex_token_iterator::iterator_category

typedef std::forward_iterator_tag iterator_category;

The type is a synonym for std::forward_iterator_tag.

regex_token_iterator::pointer

typedef sub_match<BidIt> *pointer;

The type is a synonym for sub_match<BidIt>*, where BidIt is the template parameter.

regex_token_iterator::reference

typedef sub_match<BidIt>& reference;

The type is a synonym for sub_match<BidIt>&, where BidIt is the template parameter.

regex_token_iterator::regex_type

typedef basic_regex<Elem, RXtraits> regex_type;

The typedef is a synonym for basic_regex<Elem, RXtraits>.

regex_token_iterator::value_type

typedef sub_match<BidIt> value_type;

The type is a synonym for sub_match<BidIt>, where BidIt is the template parameter.

Member functions
regex_token_iterator::operator==

bool operator==(const regex_token_iterator& right);

The member function returns it == right.it && subs == right.subs && pos == right.pos.

regex_token_iterator::operator!=

bool operator!=(const regex_token_iterator& right);

The member function returns !(*this == right).

regex_token_iterator::operator*

const sub_match<BidIt>& operator*();

The member function returns a sub_match<BidIt> object representing the capture group identified by the index value subs[pos].

regex_token_iterator::operator->

const sub_match<BidIt> *operator->();

The member function returns a pointer to a sub_match<BidIt> object representing the capture group identified by the index value subs[pos].

Operators
regex_token_iterator::operator++

regex_token_iterator& operator++();
regex_token_iterator& operator++(int);

If the stored iterator it is an end-of-sequence iterator the first operator sets the stored value pos to the value of subs.size() (thus making an end-of-sequence iterator). Otherwise the operator increments the stored value pos; if the result is equal to the value subs.size() it sets the stored value pos to 0 and increments the stored iterator it. If incrementing the stored iterator leaves it unequal to an end-of-sequence iterator the operator does nothing further. Otherwise, if the end of the preceding match was at the end of the character sequence the operator sets the stored value of pos to subs.size(). Otherwise, the operator repeatedly increments the stored value pos until pos == subs.size() or subs[pos] == -1 (thus ensuring that the next dereference of the iterator will return the tail of the character sequence if one of the index values is -1). In all cases the operator returns the object.

The second operator makes a copy of the object, increments the object, then returns the copy.

regex_traits

Description
Synopsis
Constructor
regex_traits::regex_traits
Types
regex_traits::char_class_type
regex_traits::char_type
regex_traits::locale_type
regex_traits::size_type
regex_traits::string_type
Member functions
regex_traits::getloc
regex_traits::imbue
regex_traits::isctype
regex_traits::length
regex_traits::lookup_classname
regex_traits::lookup_collatename
regex_traits::value
regex_traits::transform
regex_traits::transform_primary
regex_traits::translate
regex_traits::translate_nocase
Description

The template class describes various regular expression traits for type Elem. The template class basic_regex uses this information to manipulate elements of type Elem.

Each regex_traits object holds an object of type regex_traits::locale which is used by some of its member functions. The default locale is a copy of regex_traits::locale(). The member function imbue replaces the locale object, and the member function getloc returns a copy of the locale object.

Synopsis
template<class Elem>
    struct regex_traits {
    regex_traits();

    static size_type length(const char_type *str);
    char_type translate(char_type ch) const;
    char_type translate_nocase(char_type ch) const;
    template<class FwdIt>
        string_type transform(FwdIt first, FwdIt last) const;
    template<class FwdIt>
        string_type transform_primary(FwdIt first, FwdIt last) const;

    template<class FwdIt>
        char_class_type lookup_classname(FwdIt first, FwdIt last) const;
    template<class FwdIt>
        string_type lookup_collatename(FwdIt first, FwdIt last) const;
    bool isctype(char_type ch, char_class_type cls) const;

    int value(Elem ch, int base) const;

    locale_type imbue(locale_type loc);
    locale_type getloc() const;

    typedef Elem char_type;
    typedef T6 size_type;
    typedef basic_string<Elem> string_type;
    typedef T7 locale_type;
    typedef T8 char_class_type;
    };
Constructor
regex_traits::regex_traits

regex_traits();

The constructor constructs an object whose stored locale object is initialized to the default locale.

Types
regex_traits::char_class_type

typedef T8 char_class_type;

The type is a synonym for an unspecified type that designates character classes. Values of this type can be combined using the | operator to designate character classes that are the union of the classes designated by the operands.

regex_traits::char_type

typedef Elem char_type;

The typedef is a synonym for the template argument Elem.

regex_traits::locale_type

typedef T7 locale_type;

The typedef is a synonym for a type that encapsulates locales. In the specializations regex_traits<char> and regex_traits<wchar_t> it is a synonym for std::locale.

regex_traits::size_type

typedef T6 size_type;

The typedef is a synonym for an unsigned integral type. In the specializations regex_traits<char> and regex_traits<wchar_t> it is a synonym for std::size_t.

The typedef is a synonym for std::size_t.

regex_traits::string_type

typedef basic_string<Elem> string_type;

The typedef is a synonym for basic_string<Elem>.

Member functions
regex_traits::getloc

locale_type getloc() const;

The member function returns the stored locale object.

regex_traits::imbue

locale_type imbue(locale_type loc);

The member function copies loc to the stored locale object and returns a copy of the previous value of the stored locale object.

regex_traits::isctype

bool isctype(char_type ch, char_class_type cls) const;

The member function returns true only if the character ch is in the character class designated by cls.

regex_traits::length

static size_type length(const char_type *str);

The static member function returns std::char_traits<char_type>::length(str).

regex_traits::lookup_classname

template<class FwdIt>
    char_class_type lookup_classname(FwdIt first, FwdIt last) const;

The member function returns a value that designates the character class named by the character sequence pointed to by its arguments. The value does not depend on the case of the characters in the sequence.

The specialization regex_traits<char> recognizes the names “d”, “s”, “w”, “alnum”, “alpha”, “blank”, “cntrl”, “digit”, “graph”, “lower”, “print”, “punct”, “space”, “upper”, and “xdigit”, all without regard to case.

The specialization regex_traits<wchar_t> recognizes the names L“d”, L“s”, L“w”, L“alnum”, L“alpha”, L“blank”, L“cntrl”, L“digit”, L“graph”, L“lower”, L“print”, L“punct”, L“space”, L“upper”, and L“xdigit”, all without regard to case.

regex_traits::lookup_collatename

template<class FwdIt>
string_type lookup_collatename(FwdIt first, FwdIt last) const;

xxx

regex_traits::value

int value(Elem ch, int radix) const;

The member function returns the value represented by the character ch in the base radix, or -1 if ch is not a valid digit in the base radix. The function will only be called with a radix argument of 8, 10, or 16.

regex_traits::transform

template<class FwdIt>
string_type transform(FwdIt first, FwdIt last) const;

The member function returns a string that it generates by using a transformation rule that depends on the stored locale object. For two character sequences designated by the iterator ranges [first1, last1) and [first2, last2), transform(first1, last1) < transform(first2, last2) if the character sequence designated by the iterator range [first1, last1) sorts before the character sequence designated by the iterator range [first2, last2).

regex_traits::transform_primary

template<class FwdIt>
string_type transform_primary(FwdIt first, FwdIt last) const;

The member function returns a string that it generates by using a transformation rule that depends on the stored locale object. For two character sequences designated by the iterator ranges [first1, last1) and [first2, last2), transform_primary(first1, last1) < transform_primary(first2, last2) if the character sequence designated by the iterator range [first1, last1) sorts before the character sequence designated by the iterator range [first2, last2) without regard for case or accents.

regex_traits::translate

char_type translate(char_type ch) const;

The member function returns a character that it generates by using a transformation rule that depends on the stored locale object. For two char_type objects ch1 and ch2, translate(ch1) == translate(ch2) only if ch1 and ch2 should match when one occurs in the regular expression definition and the other occurs at a corresponding position in the target sequence for a (locale-sensitive) match.

regex_traits::translate_nocase

char_type translate_nocase(char_type ch) const;

The member function returns a character that it generates by using a transformation rule that depends on the stored locale object. For two char_type objects ch1 and ch2, translate_nocase(ch1) == translate_nocase(ch2) only if ch1 and ch2 should match when one occurs in the regular expression definition and the other occurs at a corresponding position in the target sequence for a (case-insensitive) match.

regex_traits<char>

template <>
    class regex_traits<char>

The class is an explicit specialization of template class regex_traits for elements of type char (so that it can take advantage of library functions that manipulate objects of this type).

regex_traits<wchar_t>

template <>
    class regex_traits<wchar_t>

The class is an explicit specialization of template class regex_traits for elements of type wchar_t (so that it can take advantage of library functions that manipulate objects of this type).

sub_match

Description
Synopsis
Types
sub_match::difference_type
sub_match::iterator
sub_match::value_type
Member functions
sub_match::compare
sub_match::length
sub_match::str
Members
sub_match::matched
Operators
sub_match::operator basic_string<value_type>
Description

The template class describes an object that designates a sequence of characters that matched a capture group in a call to regex_match or to regex_search. Objects of type match_results hold an array of these objects, one for each capture group in the regular expression that was used in the search.

If the capture group was not matched the object's data member matched holds false, and the two iterators first and second (inherited from the base std::pair) are equal. If the capture group was matched, matched holds true, the iterator first points to the first character in the target sequence that matched the capture group, and the iterator second points one position past the last character in the target sequence that matched the capture group. Note that for a zero-length match the member matched holds true, the two iterators will be equal, and both will point to the position of the match.

A zero-length match can occur when a capture group consists solely of an assertion, or of a repetition that allows zero repeats. For example:

Synopsis
template<class BidIt>
    class sub_match : public std::pair<BidIt, BidIt>{
public:
    bool matched;

    int compare(const sub_match& right) const;
    int compare(const basic_string<value_type>& right) const;
    int compare(const value_type *right) const;

    difference_type length() const;
    operator basic_string<value_type>() const;
    basic_string<value_type> str() const;

    typedef typename iterator_traits<BidIt>::value_type value_type;
    typedef typename iterator_traits<BidIt>::difference_type difference_type;
    typedef BidIt iterator;
    };
Types
sub_match::difference_type

typedef typename iterator_traits<BidIt>::difference_type difference_type;

The typedef is a synonym for iterator_traits<BidIt>::difference_type.

sub_match::iterator

typedef BidIt iterator;

The typedef is a synonym for the template type argument Bidit.

sub_match::value_type

typedef typename iterator_traits<BidIt>::value_type value_type;

The typedef is a synonym for iterator_traits<BidIt>::value_type.

Member functions
sub_match::compare

int compare(const sub_match& right) const;
int compare(const basic_string<value_type>& right) const;
int compare(const value_type *right) const;

The first member function compares the matched sequence [first, second) to the matched sequence [right.first, right.second). The second member function compares the matched sequence [first, second) to the character sequence [right.begin(), right.end()). The third member function compares the matched sequence [first, second) to the character sequence [right, right + std::char_traits<value_type>::length(right)).

Each function returns:

sub_match::length

difference_type length() const;

The member function returns the length of the matched sequence, or 0 if there was no matched sequence.

sub_match::str

basic_string<value_type> str() const;

The member function returns basic_string<value_type>(first, second).

Members
sub_match::matched

bool matched;

The member holds true only if the capture group associated with *this was part of the regular expression match.

Operators
sub_match::operator basic_string<value_type>

operator basic_string<value_type>() const;

The member operator returns str().

Template functions

regex_match
regex_replace
regex_search
swap

regex_match

template<class BidIt, class Alloc, class Elem, class RXtraits, class Alloc2>
    bool regex_match(BidIt first, Bidit last,
        match_results<BidIt, Alloc>& match,
        const basic_regex<Elem, RXtraits, Alloc2>& re,
        match_flag_type flags = match_default);
template<class BidIt, class Elem, class RXtraits, class Alloc2>
    bool regex_match(BidIt first, Bidit last,
        const basic_regex<Elem, RXtraits, Alloc2>& re,
        match_flag_type flags = match_default);
template<class Elem, class Alloc, class RXtraits, class Alloc2>
    bool regex_match(const Elem *ptr,
        match_results<const Elem*, Alloc>& match,
        const basic_regex<Elem, RXtraits, Alloc2>& re,
        match_flag_type flags = match_default);
template<class Elem, class RXtraits, class Alloc2>
    bool regex_match(const Elem *ptr,
        const basic_regex<Elem, RXtraits, Alloc2>& re,
        match_flag_type flags = match_default);
template<class IOtraits, class IOalloc, class Alloc, class Elem, 
    class RXtraits, class Alloc2>
    bool regex_match(
    const basic_string<Elem, IOtraits, IOalloc>& str,
    match_results<typename basic_string<Elem, IOtraits, IOalloc>::const_iterator,
    Alloc>& match,
    const basic_regex<Elem, RXtraits, Alloc2>& re,
    match_flag_type flags = match_default);
template<class IOtraits, class IOalloc, class Elem, class RXtraits, class Alloc2>
    bool regex_match(const basic_string<Elem, IOtraits, IOalloc>& str,
        const basic_regex<Elem, RXtraits, Alloc2>& re,
        match_flag_type flags = match_default);

Each template function returns true only if its operand sequence exactly matches its regular expression argument re. The functions that take a match_results object set its members to reflect whether the match succeeded and if so what the various capture groups in the regular expression captured.

regex_replace

template<class OutIt, class BidIt, class RXtraits, class Alloc, class Elem>
    OutIt regex_replace(OutIt out,
        BidIt first, BidIt last,
        const basic_regex<Elem, RXtraits, Alloc>& re,
        const basic_string<Elem>& fmt,
        match_flag_type flags = match_default);
template<class RXtraits, class Alloc, class Elem>
    basic_string<Elem> regex_replace(const basic_string<Elem>& str,
        const basic_regex<Elem, RXtraits, Alloc>& re,
        const basic_string<Elem>& fmt,
        match_flag_type flags = match_default);

The first function constructs a regex_iterator object iter(first, last, re, flags) and uses it to split its input range [first, last) into a series of subsequences T0M0T1M1...TN-1MN-1TN, where Mn is the nth match detected by the iterator. If no matches are found, T0 is the entire input range and N is 0. If (flags & format_first_only) != 0 only the first match is used, T1 is all of the input text that follows the match, and N is 1. For each i in the range [0, N), if (flags & format_no_copy) == 0 it copies the text in the range Ti to the iterator out. It then calls m.format(out, fmt, flags), where m is the match_results object returned by the iterator object iter for the subsequence Mi. Finally, if (flags & format_no_copy) == 0 it copies the text in the range TN to the iterator out. The function returns out.

The second function constructs a local variable result of type basic_string<charT> and calls regex_replace(back_inserter(result), str.begin(), str.end(), re, fmt, flags). It returns result.

template<class BidIt, class Alloc, class Elem, class RXtraits>
    bool regex_search(BidIt first, Bidit last,
        match_results<BidIt, Alloc>& match,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);
 template<class BidIt, class Elem, class RXtraits>
    bool regex_search(BidIt first, Bidit last,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);
 template<class Elem, class Alloc, class RXtraits>
    bool regex_search(const Elem* ptr,
        match_results<const Elem*, Alloc>& match,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);
 template<class Elem, class RXtraits>
    bool regex_search(const Elem* ptr,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);
 template<class IOtraits, class IOalloc, class Alloc, class Elem, class RXtraits>
    bool regex_search(
        const basic_string<Elem, IOtraits, IOalloc>& str,
        match_results<typename basic_string<Elem, IOtraits, IOalloc>::
        const_iterator, Alloc>& match, const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);
 template<class IOtraits, class IOalloc, class Elem, class RXtraits
>    bool regex_search(
        const basic_string<Elem, IOtraits, IOalloc>& str,
        const basic_regex<Elem, RXtraits>& re,
        match_flag_type flags = match_default);

Each template function returns true only if a search for its regular expression argument re in its operand sequence succeeds. The functions that take a match_results object set its members to reflect whether the search succeeded and if so what the various capture groups in the regular expression captured.

swap

template<class Elem, class RXtraits>
    void swap(basic_regex<Elem, RXtraits, Alloc>& left,
        basic_regex<Elem, RXtraits>& right) throw();
template<class Elem, class IOtraits, class BidIt, class Alloc>
    void swap(match_results<BidIt, Alloc>& left,
        match_results<BidIt, Alloc>& right) throw();

The template functions swap the contents of their respective arguments in constant time and do not throw exceptions.

Types

cmatch
cregex_iterator
cregex_token_iterator
csub_match
regex
regex_constants
regex_constants::error_type
regex_constants::match_flag_type
regex_constants::syntax_option_type
smatch
sregex_iterator
sregex_token_iterator
ssub_match
wcmatch
wcregex_iterator
wcregex_token_iterator
wcsub_match
wsmatch
wsregex_iterator
wsregex_token_iterator
wssub_match
wregex

cmatch

typedef match_results<const char*> cmatch;

The type describes a specialization of template class match_results for iterators of type const char*.

cregex_iterator

typedef regex_iterator<const char*> cregex_iterator;

The type describes a specialization of template class regex_iterator for iterators of type const char*.

cregex_token_iterator

typedef regex_token_iterator<const char*> cregex_token_iterator;

The type describes a specialization of template class regex_token_iterator for iterators of type const char*.

csub_match

typedef sub_match<const char*> csub_match;

The type describes a specialization of template class sub_match for iterators of type const char*.

regex

typedef basic_regex<char> regex;

The type describes a specialization of template class basic_regex for elements of type char.

regex_constants

namespace regex_constants {
  typedef T1 syntax_option_type;
  typedef T2 match_flag_type;
  typedef T3 error_type;
  }
regex_constants::error_type

typedef T3 error_type;
static const error_type error_badbrace, error_badrepeat, error_brace,
  error_brack, error_collate, error_complexity, error_ctype,
  error_escape, error_paren, error_range, error_space,
  error_stack, error_backref;

The type is an enumerated type that describes an object that can hold error flags. The distinct flag values are:

regex_constants::match_flag_type

typedef T2 match_flag_type;
static const match_flag_type match_any, match_default, match_not_bol,
  match_not_bow, match_continuous, match_not_eol, match_not_eow,
  match_not_null, match_partial, match_prev_avail;

The type is a bitmask type that describes options to be used when matching a text sequence against a regular expression and format flags to be used when replacing text. Options can be combined with |.

The match options are:

The format flags are:

regex_constants::syntax_option_type

typedef T1 syntax_option_type;
static const syntax_option_type awk, basic, collate, ECMAScript,
  egrep, extended, grep, icase, nosubs, optimize;

The type is a bitmask type that describes language specifiers and syntax modifiers to be used when compiling a regular expression. Options can be combined with |. No more than one language specifier should be used at a time.

The language specifiers are:

The syntax modifiers are:

smatch

typedef match_results<string::const_iterator> smatch;

The type describes a specialization of template class match_results for iterators of type string::const_iterator.

sregex_iterator

typedef regex_iterator<string::const_iterator> sregex_iterator;

The type describes a specialization of template class regex_iterator for iterators of type string::const_iterator.

sregex_token_iterator

typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;

The type describes a specialization of template class regex_token_iterator for iterators of type string::const_iterator.

ssub_match

typedef sub_match<string::const_iterator> ssub_match;

The type describes a specialization of template class sub_match for iterators of type string::const_iterator.

wcmatch

typedef match_results<const wchar_t *> wcmatch;

The type describes a specialization of template class match_results for iterators of type const wchar_t*.

wcregex_iterator

typedef regex_iterator<const wchar_t*> wcregex_iterator;

The type describes a specialization of template class regex_iterator for iterators of type const wchar_t*.

wcregex_token_iterator

typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;

The type describes a specialization of template class regex_token_iterator for iterators of type const wchar_t*.

wcsub_match

typedef sub_match<const wchar_t*> wcsub_match;

The type describes a specialization of template class sub_match for iterators of type const wchar_t*.

wsmatch

typedef match_results<wstring::const_iterator> wsmatch;

The type describes a specialization of template class match_results for iterators of type wstring::const_iterator.

wsregex_iterator

typedef regex_iterator<wstring::const_iterator> wsregex_iterator;

The type describes a specialization of template class regex_iterator for iterators of type wstring::const_iterator.

wsregex_token_iterator

typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;

The type describes a specialization of template class regex_token_iterator for iterators of type wstring::const_iterator.

wssub_match

typedef sub_match<wstring::const_iterator> wssub_match;

The type describes a specialization of template class sub_match for iterators of type wstring::const_iterator.

wregex

typedef basic_regex<wchar_t> wregex;

The type describes a specialization of template class basic_regex for elements of type wchar_t.

Operators

operator==
operator!=
operator<
operator<=
operator>
operator>=
operator<<

operator==

template<class BidIt>
    bool operator==(
        const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator==(
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator==(
        const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& right);
template<class BidIt>
    bool operator==(
        const typename iterator_traits<BidIt>::value_type* left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator==(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type* right);
template<class BidIt>
    bool operator==(
        const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator==(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);
template<class BidIt, class Alloc>
    bool operator==(
        const match_results<BidIt, Alloc>& left,
        const match_results<BidIt, Alloc>& right);

Each template operator converts each of its arguments to a string type and returns the result of comparing the converted objects for equality.

When a template operator converts its arguments to a string type it uses the first of the following transformations that applies:

operator!=

template<class BidIt>
    bool operator!=(
        const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator!=(
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator!=(
        const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& right);
template<class BidIt>
    bool operator!=(
        const typename iterator_traits<BidIt>::value_type *left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator!=(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type *right);
template<class BidIt>
    bool operator!=(
        const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator!=(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);
template<class BidIt, class Alloc>
    bool operator!=(
        const match_results<BidIt, Alloc>& left,
        const match_results<BidIt, Alloc>& right);

Each template operator returns !(left == right).

operator<

template<class BidIt>
    bool operator<(
        const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator<(
        const basic_string<typename iterator_traits<BidIt>::value_type,
        IOtraits, Alloc>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator<(
        const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& right);
template<class BidIt>
    bool operator<(
        const typename iterator_traits<BidIt>::value_type *left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator<(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type *right);
template<class BidIt>
    bool operator<(
        const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator<(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);

Each template operator converts its arguments to a string type and returns true only if the converted value of left compares less than the converted value of right.

operator<=

template<class BidIt>
    bool operator<=(
        const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator<=(
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator<=(
        const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& right);
template<class BidIt>
    bool operator<=(
        const typename iterator_traits<BidIt>::value_type *left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator<=(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type *right);
template<class BidIt>
    bool operator<=(
        const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator<=(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);

Each template operator returns !(right < left).

operator>

template<class BidIt>
    bool operator>(
        const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator>(
        const basic_string<typename iterator_traits<BidIt>::value_type,
        IOtraits, Alloc>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator>(
        const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& right);
template<class BidIt>
    bool operator>(
        const typename iterator_traits<BidIt>::value_type *left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator>(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type *right);
template<class BidIt>
    bool operator>(
        const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator>(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);

Each template operator returns right < left.

operator>=

template<class BidIt>
    bool operator>=(
        const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator>=(
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator>=(
        const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type, 
        IOtraits, Alloc>& right);
template<class BidIt>
    bool operator>=(
        const typename iterator_traits<BidIt>::value_type *left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator>=(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type *right);
template<class BidIt>
    bool operator>=(
        const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator>=(
        const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);

Each template operator returns !(left < right).

operator<<

template<class Elem, class IOtraits, class Alloc, class BidIt>
    basic_ostream<Elem, IOtraits>&
    operator<<(
        basic_ostream<Elem, IOtraits>& os,
        const sub_match<BidIt>& right);

The template operator returns os << right.str().

Copyright note

Certain materials included or referred to in this document are copyright P.J. Plauger and/or Dinkumware, Ltd. or are based on materials that are copyright P.J. Plauger and/or Dinkumware, Ltd.

Notwithstanding the meta-data for this document, copyright information for this document is as follows:

Copyright © IBM Corp. 1999, 2010. & Copyright © P.J. Plauger and/or Dinkumware, Ltd. 1992-2006.