Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/regex/match results"

From cppreference.com
< cpp‎ | regex
m (Update links.)
m (Use since= and until= params of {{ddcl}} template.)
Line 1: Line 1:
 
{{cpp/title|match_results}}
 
{{cpp/title|match_results}}
 
{{cpp/regex/match_results/navbar}}
 
{{cpp/regex/match_results/navbar}}
{{ddcl | header=regex | notes={{mark since c++11}} | 1=
+
{{ddcl | header=regex | sincec++11 | 1=
 
template<
 
template<
 
     class BidirIt,
 
     class BidirIt,

Revision as of 18:31, 9 July 2013

 
 
 
Regular expressions library
Classes
(C++11)
match_results
(C++11)
Algorithms
Iterators
Exceptions
Traits
Constants
(C++11)
Regex Grammar
 
 
Defined in header <regex>
template<

    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.

Contents

Type requirements

Template:par req conceptTemplate:par req concept

Specializations

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

constructs the object
(public member function) [edit]
destructs the object
(public member function) [edit]
assigns the contents
(public member function) [edit]
returns the associated allocator
(public member function) [edit]
State

(public member function)
Size
checks whether the match was successful
(public member function) [edit]
returns the number of matches in a fully-established result state
(public member function) [edit]
returns the maximum possible number of sub-matches
(public member function) [edit]
Element access
returns the length of the particular sub-match
(public member function) [edit]
returns the position of the first character of the particular sub-match
(public member function) [edit]
returns the sequence of characters for the particular sub-match
(public member function) [edit]
returns specified sub-match
(public member function) [edit]
returns sub-sequence between the beginning of the target sequence and the beginning of the full match
(public member function) [edit]
returns sub-sequence between the end of the full match and the end of the target sequence
(public member function) [edit]
Iterators
returns iterator to the beginning of the list of sub-matches
(public member function) [edit]
returns iterator to the end of the list of sub-matches
(public member function) [edit]
Format
formats match results for output
(public member function) [edit]
Modifiers
swaps the contents
(public member function) [edit]

Non-member functions

(removed in C++20)
lexicographically compares the values in the two match result
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]