Difference between revisions of "cpp/regex/match results"
From cppreference.com
m (r2.7.3) (Robot: Adding de, es, fr, it, ja, pt, ru, zh) |
(I'm going to assert that empty parens add more confusion than they remove, e.g. "is that a function call?" or "does that take zero arguments?") |
||
Line 10: | Line 10: | ||
The class template {{c|std::match_results}} holds a collection of character sequences that represent the result of a regular expression match. | The class template {{c|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 or modified by passing to the {{c|std::regex_search | + | This is a specialized allocator-aware container. It can only be default created or modified by passing to the {{c|std::regex_search}} or {{c|std::regex_match}} algorithms. |
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. | 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. |
Revision as of 15:41, 16 January 2013
Defined in header <regex>
|
||
template< class BidirIt, |
(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 or modified by passing to the std::regex_search or std::regex_match algorithms.
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
-BidirIt must meet the requirements of LegacyBidirectionalIterator.
| ||
-Alloc must meet the requirements of Allocator.
|
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> |