Namespaces
Variants
Actions

std::regex_iterator

From cppreference.com
< cpp‎ | regex
 
 
 
Regular expressions library
Classes
(C++11)
Algorithms
Iterators
regex_iterator
(C++11)
Exceptions
Traits
Constants
(C++11)
Regex Grammar
 
 
Defined in header <regex>
template<

    class BidirIt,
    class CharT = typename std::iterator_traits<BidirIt>::value_type,
    class Traits = std::regex_traits<CharT>

> class regex_iterator
(since C++11)

std::regex_iterator is a read-only iterator that accesses the individual matches of a regular expression within the underlying character sequence. It meets the requirements of a LegacyForwardIterator, except that for dereferenceable values a and b with a == b, *a and *b will not be bound to the same object.

On construction, and on every increment, it calls std::regex_search and remembers the result (that is, saves a copy of the std::match_results<BidirIt> value). The first object may be read when the iterator is constructed or when the first dereferencing is done. Otherwise, dereferencing only returns a copy of the most recently obtained regex match.

The default-constructed std::regex_iterator is the end-of-sequence iterator. When a valid std::regex_iterator is incremented after reaching the last match (std::regex_search returns false), it becomes equal to the end-of-sequence iterator. Dereferencing or incrementing it further invokes undefined behavior.

A typical implementation of std::regex_iterator holds the begin and the end iterators for the underlying sequence (two instances of BidirIt), a pointer to the regular expression (const regex_type*), the match flags (std::regex_constants::match_flag_type), and the current match (std::match_results<BidirIt>).

Contents

[edit] Type requirements

-
BidirIt must meet the requirements of LegacyBidirectionalIterator.

[edit] Specializations

Several specializations for common character sequence types are defined:

Defined in header <regex>
Type Definition
std::cregex_iterator std::regex_iterator<const char*>
std::wcregex_iterator std::regex_iterator<const wchar_t*>
std::sregex_iterator std::regex_iterator<std::string::const_iterator>
std::wsregex_iterator std::regex_iterator<std::wstring::const_iterator>

[edit] Member types

Type Definition
value_type std::match_results<BidirIt>
difference_type std::ptrdiff_t
pointer const value_type*
reference const value_type&
iterator_category std::forward_iterator_tag
iterator_concept (C++20) std::input_iterator_tag
regex_type std::basic_regex<CharT, Traits>

[edit] Data members

Member Description
BidiIt begin (private) the begin iterator
(exposition-only member object*)
BidiIt end (private) the end iterator
(exposition-only member object*)
const regex_type* pregex (private) a pointer to a regular expression
(exposition-only member object*)
regex_constants::match_flag_type flags (private) a flag
(exposition-only member object*)
match_results<BidiIt> match (private) the current match
(exposition-only member object*)

[edit] Member functions

constructs a new regex_iterator
(public member function) [edit]
(destructor)
(implicitly declared)
destructs a regex_iterator, including the cached value
(public member function) [edit]