From cppreference.com
Defined in header
template<classBidirIt,classAlloc=std::allocator<std::sub_match<BidirIt>>>classmatch_results; (1) (since C++11)namespacepmr{template<classBidirIt>usingmatch_results=std::match_results<BidirIt,std::pmr::polymorphic_allocator<std::sub_match<BidirIt>>>;} (2) (since C++17)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
, or modified by
or
. Because std::match_results holds
es, 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
(index 0) contained in a std::match_result always represents the full match within a target sequence made by a regex, and subsequent
es represent sub-expression matches corresponding in sequence to the left parenthesis delimiting the sub-expression in the regex.
std::match_results meets the requirements of a
and of a
, except that only copy assignment, move assignment, and operations defined for a constant containers are supported, and that the semantics of comparison functions are different from those required for a container.
Type requirements
Specializations
Several specializations for common character sequence types are provided:
Defined in header
Type Definition std::cmatchstd::match_results<constchar*>std::wcmatchstd::match_results<constwchar_t*>std::smatchstd::match_results<std::string::const_iterator>std::wsmatchstd::match_results<std::wstring::const_iterator>std::pmr::cmatch(C++17)std::pmr::match_results<constchar*>std::pmr::wcmatch(C++17)std::pmr::match_results<constwchar_t*>std::pmr::smatch(C++17)std::pmr::match_results<std::string::const_iterator>std::pmr::wsmatch(C++17)std::pmr::match_results<std::wstring::const_iterator>Member types
Member type Definition allocator_typeAllocatorvalue_typestd::sub_match<BidirIt>const_referenceconstvalue_type&referencevalue_type&const_iteratorimplementation-defined (depends on the underlying container) iteratorconst_iteratordifference_typestd::iterator_traits<BidirIt>::difference_typesize_typestd::allocator_traits<Alloc>::size_typechar_typestd::iterator_traits<BidirIt>::value_typestring_typestd::basic_string<char_type>Member functions
constructs the object
(public member function)
destructs the object
(public member function)
assigns the contents
(public member function)
returns the associated allocator
(public member function)
State
checks if the results are available
(public member function) Size
checks whether the match was successful
(public member function)
returns the number of matches in a fully-established result state
(public member function)
returns the maximum possible number of sub-matches
(public member function)
Element access
returns the length of the particular sub-match
(public member function)
returns the position of the first character of the particular sub-match
(public member function)
returns the sequence of characters for the particular sub-match
(public member function)
returns specified sub-match
(public member function)
returns sub-sequence between the beginning of the target sequence and the beginning of the full match
(public member function)
returns sub-sequence between the end of the full match and the end of the target sequence
(public member function)
Iterators
returns iterator to the beginning of the list of sub-matches
(public member function)
returns iterator to the end of the list of sub-matches
(public member function)
Format
formats match results for output
(public member function)
Modifiers
swaps the contents
(public member function)
Non-member functions