Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | regex
(warning about invalidation of iterators)
m (Shorten template names. Use {{lc}} where appropriate.)
Line 8: Line 8:
 
}}
 
}}
  
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 {{|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 {{c|std::regex_iterator}}, or modified by {{c|std::regex_search}} or {{c|std::regex_match}}. Because {{tt|std::match_results}} holds {{c|std::sub_match}}es, each of which is a pair of iterators into the original character sequence that was matched, it's undefined behavior to examine {{tt|std::match_results}} if the original character sequence was destroyed or iterators to it were invalidated for other reasons.
+
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 {{tt|std::match_results}} holds {{|std::sub_match}}es, each of which is a pair of iterators into the original character sequence that was matched, it's undefined behavior to examine {{tt|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.
 
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===
 
===Type requirements===
{{param list begin}}
+
{{begin}}
{{param list req concept | BidirIt | BidirectionalIterator}}
+
{{req concept | BidirIt | BidirectionalIterator}}
{{param list req concept | Alloc | Allocator}}
+
{{req concept | Alloc | Allocator}}
{{param list end}}
+
{{end}}
  
 
===Specializations===
 
===Specializations===
 
Several specializations for common character sequence types are provided:  
 
Several specializations for common character sequence types are provided:  
  
{{dcl list begin}}
+
{{begin}}
{{dcl list header | regex}}
+
{{header | regex}}
{{dcl list hitem | Type | Definition}}
+
{{hitem | Type | Definition}}
{{dcl list item | {{tt|cmatch}} | {{c|match_results<const char*>}}}}
+
{{| {{tt|cmatch}} | {{c|match_results<const char*>}}}}
{{dcl list item | {{tt|wcmatch}} | {{c|match_results<const wchar_t*>}}}}
+
{{| {{tt|wcmatch}} | {{c|match_results<const wchar_t*>}}}}
{{dcl list item | {{tt|smatch}} | {{c|match_results<std::string::const_iterator>}}}}
+
{{| {{tt|smatch}} | {{c|match_results<std::string::const_iterator>}}}}
{{dcl list item | {{tt|wsmatch}} | {{c|match_results<std::wstring::const_iterator>}}}}
+
{{| {{tt|wsmatch}} | {{c|match_results<std::wstring::const_iterator>}}}}
{{dcl list end}}
+
{{end}}
  
 
===Member types===
 
===Member types===
{{dcl list begin}}
+
{{begin}}
{{dcl list hitem | Member type | Definition}}
+
{{hitem | Member type | Definition}}
{{dcl list item | {{tt|allocator_type}} | {{c|Allocator}}}}
+
{{| {{tt|allocator_type}} | {{c|Allocator}}}}
{{dcl list item | {{tt|value_type}} | {{c|std::sub_match<BidirIt>}}}}
+
{{| {{tt|value_type}} | {{c|std::sub_match<BidirIt>}}}}
{{dcl list item | {{tt|const_reference}} | {{c|const value_type&}}}}
+
{{| {{tt|const_reference}} | {{c|const value_type&}}}}
{{dcl list item | {{tt|reference}} | {{c|const_reference}}}}
+
{{| {{tt|reference}} | {{c|const_reference}}}}
{{dcl list item | {{tt|const_iterator}} | ''implementation defined'' (depends on the underlying container)}}
+
{{| {{tt|const_iterator}} | ''implementation defined'' (depends on the underlying container)}}
{{dcl list item | {{tt|iterator}} | {{c|const_iterator}}}}
+
{{| {{tt|iterator}} | {{c|const_iterator}}}}
{{dcl list item | {{tt|difference_type}} | {{c|std::iterator_traits<BidirIt>::difference_type}}}}
+
{{| {{tt|difference_type}} | {{c|std::iterator_traits<BidirIt>::difference_type}}}}
{{dcl list item | {{tt|size_type}} | {{c|std::allocator_traits<Alloc>::size_type}}}}
+
{{| {{tt|size_type}} | {{c|std::allocator_traits<Alloc>::size_type}}}}
{{dcl list item | {{tt|char_type}} | {{c|std::iterator_traits<BidirIt>::value_type}}}}
+
{{| {{tt|char_type}} | {{c|std::iterator_traits<BidirIt>::value_type}}}}
{{dcl list item | {{tt|string_type}} | {{c|std::basic_string<char_type>}}}}
+
{{| {{tt|string_type}} | {{c|std::basic_string<char_type>}}}}
{{dcl list end}}
+
{{end}}
  
 
===Member functions===
 
===Member functions===
{{dcl list begin}}
+
{{begin}}
{{dcl list template | cpp/regex/match_results/dcl list constructor}}
+
{{| cpp/regex/match_results/dcl list constructor}}
{{dcl list template | cpp/regex/match_results/dcl list destructor}}
+
{{| cpp/regex/match_results/dcl list destructor}}
{{dcl list template | cpp/regex/match_results/dcl list operator{{=}}}}
+
{{| cpp/regex/match_results/dcl list operator{{=}}}}
{{dcl list template | cpp/regex/match_results/dcl list get_allocator}}
+
{{| cpp/regex/match_results/dcl list get_allocator}}
  
{{dcl list h2 | State}}
+
{{h2 | State}}
{{dcl list mem fun | cpp/regex/match_results/ready | }}
+
{{mem fun | cpp/regex/match_results/ready | }}
  
{{dcl list h2 | Size}}
+
{{h2 | Size}}
{{dcl list template | cpp/regex/match_results/dcl list empty}}
+
{{| cpp/regex/match_results/dcl list empty}}
{{dcl list template | cpp/regex/match_results/dcl list size}}
+
{{| cpp/regex/match_results/dcl list size}}
{{dcl list template | cpp/regex/match_results/dcl list max_size}}
+
{{| cpp/regex/match_results/dcl list max_size}}
  
{{dcl list h2 | Element access}}
+
{{h2 | Element access}}
{{dcl list template | cpp/regex/match_results/dcl list length}}
+
{{| cpp/regex/match_results/dcl list length}}
{{dcl list template | cpp/regex/match_results/dcl list position}}
+
{{| cpp/regex/match_results/dcl list position}}
{{dcl list template | cpp/regex/match_results/dcl list str}}
+
{{| cpp/regex/match_results/dcl list str}}
{{dcl list template | cpp/regex/match_results/dcl list operator_at}}
+
{{| cpp/regex/match_results/dcl list operator_at}}
{{dcl list template | cpp/regex/match_results/dcl list prefix}}
+
{{| cpp/regex/match_results/dcl list prefix}}
{{dcl list template | cpp/regex/match_results/dcl list suffix}}
+
{{| cpp/regex/match_results/dcl list suffix}}
  
{{dcl list h2 | Iterators}}
+
{{h2 | Iterators}}
{{dcl list template | cpp/regex/match_results/dcl list begin}}
+
{{| cpp/regex/match_results/dcl list begin}}
{{dcl list template | cpp/regex/match_results/dcl list end}}
+
{{| cpp/regex/match_results/dcl list end}}
  
{{dcl list h2 | Format}}
+
{{h2 | Format}}
{{dcl list template | cpp/regex/match_results/dcl list format}}
+
{{| cpp/regex/match_results/dcl list format}}
  
{{dcl list h2 | Modifiers}}
+
{{h2 | Modifiers}}
{{dcl list template | cpp/regex/match_results/dcl list swap}}
+
{{| cpp/regex/match_results/dcl list swap}}
  
{{dcl list end}}
+
{{end}}
  
 
===Non-member functions===
 
===Non-member functions===
{{dcl list begin}}
+
{{begin}}
{{dcl list template | cpp/regex/match_results/dcl list operator_cmp}}
+
{{| cpp/regex/match_results/dcl list operator_cmp}}
{{dcl list template | cpp/regex/match_results/dcl list swap2}}
+
{{| cpp/regex/match_results/dcl list swap2}}
{{dcl list end}}
+
{{end}}
  
 
[[de:cpp/regex/match results]]
 
[[de:cpp/regex/match results]]

Revision as of 20:51, 31 May 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

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
State

(public member function)
Size
Element access
Iterators
Format
Modifiers

Non-member functions

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