< cpp‎ | regex
Revision as of 08:37, 18 April 2013 by Cubbi (Talk | contribs)

Defined in header <regex>

    class BidirIt,
    class Alloc = std::allocator<std::sub_match<BidirIt>>

> class match_results;
(since C++11)

The class template std::match_results holds a collection of character sequences that represent the result of a regular expression match.

This is a specialized allocator-aware container. It can only be default created, obtained from std::regex_iterator, or modified by std::regex_search or std::regex_match. Because std::match_results holds std::sub_matches, each of which is a pair of iterators into the original character sequence that was matched, it's undefined behavior to examine std::match_results if the original character sequence was destroyed or iterators to it were invalidated for other reasons.

The first sub_match (index 0) contained in a match_result always represents the full match within a target sequence made by a regex, and subsequent sub_matches represent sub-expression matches corresponding in sequence to the left parenthesis delimiting the sub-expression in the regex.


Type requirements

BidirIt must meet the requirements of BidirectionalIterator.
Alloc must meet the requirements of Allocator.


Several specializations for common character sequence types are provided:

Defined in header <regex>
Type Definition
cmatch match_results<const char*>
wcmatch match_results<const wchar_t*>
smatch match_results<std::string::const_iterator>
wsmatch match_results<std::wstring::const_iterator>

Member types

Member type Definition
allocator_type Allocator
value_type std::sub_match<BidirIt>
const_reference const value_type&
reference const_reference
const_iterator implementation defined (depends on the underlying container)
iterator const_iterator
difference_type std::iterator_traits<BidirIt>::difference_type
size_type std::allocator_traits<Alloc>::size_type
char_type std::iterator_traits<BidirIt>::value_type
string_type std::basic_string<char_type>

Member functions

Template:cpp/regex/match results/dcl list constructorTemplate:cpp/regex/match results/dcl list destructorTemplate:cpp/regex/match results/dcl list operator=Template:cpp/regex/match results/dcl list get allocatorTemplate:cpp/regex/match results/dcl list emptyTemplate:cpp/regex/match results/dcl list sizeTemplate:cpp/regex/match results/dcl list max sizeTemplate:cpp/regex/match results/dcl list lengthTemplate:cpp/regex/match results/dcl list positionTemplate:cpp/regex/match results/dcl list strTemplate:cpp/regex/match results/dcl list operator atTemplate:cpp/regex/match results/dcl list prefixTemplate:cpp/regex/match results/dcl list suffixTemplate:cpp/regex/match results/dcl list beginTemplate:cpp/regex/match results/dcl list endTemplate:cpp/regex/match results/dcl list formatTemplate:cpp/regex/match results/dcl list swap

(public member function)
Element access

Non-member functions

Template:cpp/regex/match results/dcl list operator cmpTemplate:cpp/regex/match results/dcl list swap2