[re.tokiter.general]

# 28 Text processing library [[text]](./#text)

## 28.6 Regular expressions library [[re]](re#tokiter.general)

### 28.6.11 Regular expression iterators [[re.iter]](re.iter#re.tokiter.general)

#### 28.6.11.2 Class template regex_token_iterator [[re.tokiter]](re.tokiter#general)

#### 28.6.11.2.1 General [re.tokiter.general]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12466)

The class template regex_token_iterator is an iterator adaptor; that
is to say it represents a new view of an existing iterator sequence,
by enumerating all the occurrences of a regular expression within that
sequence, and presenting one or more sub-expressions for each match
found[.](#1.sentence-1)

Each position enumerated by the iterator is a sub_match class
template instance that represents what matched a particular sub-expression
within the regular expression[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12476)

When class regex_token_iterator is used to enumerate a
single sub-expression with index â1 the iterator performs field
splitting: that is to say it enumerates one sub-expression for each section of
the character container sequence that does not match the regular
expression specified[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12483)

After it is constructed, the iterator finds and stores a valueregex_iterator<BidirectionalIterator> position and sets the internal count N to zero[.](#3.sentence-1)

It also maintains a sequencesubs which contains a list of the sub-expressions which will be
enumerated[.](#3.sentence-2)

Every time operator++ is used
the count N is incremented; if N exceeds or equals subs.size(),
then the iterator increments member position and sets count N to zero[.](#3.sentence-3)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12494)

If the end of sequence is reached (position is equal to the end of
sequence iterator), the iterator becomes equal to the end-of-sequence
iterator value, unless the sub-expression being enumerated has index â1,
in which case the iterator enumerates one last sub-expression that contains
all the characters from the end of the last regular expression match to the
end of the input sequence being enumerated, provided that this would not be an
empty sub-expression[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12503)

The default constructor constructs
an end-of-sequence iterator object, which is the only legitimate
iterator to be used for the end condition[.](#5.sentence-1)

The result of operator* on
an end-of-sequence iterator is not defined[.](#5.sentence-2)

For any other iterator value aconst sub_match<BidirectionalIterator>& is returned[.](#5.sentence-3)

The result of operator-> on an end-of-sequence iterator
is not defined[.](#5.sentence-4)

For any other iterator value a const sub_match<BidirectionalIterator>* is returned[.](#5.sentence-5)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12514)

It is impossible to store things
into regex_token_iterators[.](#6.sentence-1)

Two end-of-sequence iterators are always
equal[.](#6.sentence-2)

An end-of-sequence iterator is not equal to a
non-end-of-sequence iterator[.](#6.sentence-3)

Two non-end-of-sequence iterators are
equal when they are constructed from the same arguments[.](#6.sentence-4)

namespace std {template<class BidirectionalIterator, class charT = typename iterator_traits<BidirectionalIterator>::value_type, class traits = regex_traits<charT>>class regex_token_iterator {public:using regex_type = basic_regex<charT, traits>; using iterator_category = forward_iterator_tag; using iterator_concept = input_iterator_tag; using value_type = sub_match<BidirectionalIterator>; using difference_type = ptrdiff_t; using pointer = const value_type*; using reference = const value_type&;

 regex_token_iterator();
 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re, int submatch = 0,
 regex_constants::match_flag_type m = regex_constants::match_default);
 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re, const vector<int>& submatches,
 regex_constants::match_flag_type m = regex_constants::match_default);
 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
 initializer_list<int> submatches,
 regex_constants::match_flag_type m = regex_constants::match_default); template<size_t N> regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re, const int (&submatches)[N],
 regex_constants::match_flag_type m = regex_constants::match_default);
 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type&& re, int submatch = 0,
 regex_constants::match_flag_type m = regex_constants::match_default) = delete;
 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type&& re, const vector<int>& submatches,
 regex_constants::match_flag_type m = regex_constants::match_default) = delete;
 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type&& re,
 initializer_list<int> submatches,
 regex_constants::match_flag_type m = regex_constants::match_default) = delete; template<size_t N> regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type&& re, const int (&submatches)[N],
 regex_constants::match_flag_type m = regex_constants::match_default) = delete;
 regex_token_iterator(const regex_token_iterator&);
 regex_token_iterator& operator=(const regex_token_iterator&); bool operator==(const regex_token_iterator&) const; bool operator==(default_sentinel_t) const { return *this == regex_token_iterator(); }const value_type& operator*() const; const value_type* operator->() const;
 regex_token_iterator& operator++();
 regex_token_iterator operator++(int); private:using position_iterator = regex_iterator<BidirectionalIterator, charT, traits>; // *exposition only* position_iterator position; // *exposition only*const value_type* result; // *exposition only* value_type suffix; // *exposition only* size_t N; // *exposition only* vector<int> subs; // *exposition only*};}

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12601)

A *suffix iterator* is a regex_token_iterator object
that points to a final sequence of characters at
the end of the target sequence[.](#7.sentence-1)

In a suffix iterator the
member result holds a pointer to the data
member suffix, the value of the member suffix.match is true, suffix.first points to the beginning of the
final sequence, and suffix.second points to the end of the
final sequence[.](#7.sentence-2)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12611)

[*Note [1](#note-1)*:

For a suffix iterator, data
member suffix.first is the same as the end of the last match
found, and suffix​.second is the same as the end of the target
sequence[.](#8.sentence-1)

â *end note*]

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12619)

The *current match* is (*position).prefix() if subs[N] == -1, or(*position)[subs[N]] for any other value of subs[N][.](#9.sentence-1)
