Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Iterator class for matches.
Syntax
template<class BidIt,
class Elem = typename std::iterator_traits<BidIt>::value_type,
class RxTraits = regex_traits<Elem> >
class regex_iterator
Parameters
BidIt
The iterator type for submatches.
Elem
The type of elements to match.
RXtraits
Traits class for elements.
Remarks
The class template describes a constant forward iterator object. It extracts objects of type match_results<BidIt>
by repeatedly applying its regular expression object *pregex
to the character sequence defined by the iterator range [begin, end)
.
Constructors
Constructor | Description |
---|---|
regex_iterator | Constructs the iterator. |
Typedefs
Type name | Description |
---|---|
difference_type | The type of an iterator difference. |
iterator_category | The type of the iterator category. |
pointer | The type of a pointer to a match. |
reference | The type of a reference to a match. |
regex_type | The type of the regular expression to match. |
value_type | The type of a match. |
Operators
Operator | Description |
---|---|
operator!= | Compares iterators for inequality. |
operator* | Accesses the designated match. |
operator++ | Increments the iterator. |
operator= | Compares iterators for equality. |
operator-> | Accesses the designated match. |
Requirements
Header: <regex>
Namespace: std
Examples
See the following articles for examples on regular expressions:
// std__regex__regex_iterator.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::regex_iterator<const char *> Myiter;
int main()
{
const char *pat = "axayaz";
Myiter::regex_type rx("a");
Myiter next(pat, pat + strlen(pat), rx);
Myiter end;
for (; next != end; ++next)
std::cout << "match == " << next->str() << std::endl;
// other members
Myiter it1(pat, pat + strlen(pat), rx);
Myiter it2(it1);
next = it1;
Myiter::iterator_category cat = std::forward_iterator_tag();
Myiter::difference_type dif = -3;
Myiter::value_type mr = *it1;
Myiter::reference ref = mr;
Myiter::pointer ptr = &ref;
dif = dif; // to quiet "unused" warnings
ptr = ptr;
return (0);
}
match == a
match == a
match == a
regex_iterator::difference_type
The type of an iterator difference.
typedef std::ptrdiff_t difference_type;
Remarks
The type is a synonym for std::ptrdiff_t
.
regex_iterator::iterator_category
The type of the iterator category.
typedef std::forward_iterator_tag iterator_category;
Remarks
The type is a synonym for std::forward_iterator_tag
.
regex_iterator::operator!=
Compares iterators for inequality.
bool operator!=(const regex_iterator& right);
Parameters
right
The iterator to compare to.
Remarks
The member function returns !(*this == right)
.
regex_iterator::operator*
Accesses the designated match.
const match_results<BidIt>& operator*();
Remarks
The member function returns the stored value match
.
regex_iterator::operator++
Increments the iterator.
regex_iterator& operator++();
regex_iterator& operator++(int);
Remarks
If the current match has no characters, the first operator calls regex_search(begin, end, match, *pregex, flags | regex_constants::match_prev_avail | regex_constants::match_not_null)
; otherwise it advances the stored value begin
to point to the first character after the current match then calls regex_search(begin, end, match, *pregex, flags | regex_constants::match_prev_avail)
. In either case, if the search fails the operator sets the object to an end-of-sequence iterator. The operator returns the object.
The second operator makes a copy of the object, increments the object, then returns the copy.
regex_iterator::operator=
Compares iterators for equality.
bool operator==(const regex_iterator& right);
Parameters
right
The iterator to compare to.
Remarks
The member function returns true if *this
and right are both end-of-sequence iterators or if neither is an end-of-sequence iterator and begin == right.begin
, end == right.end
, pregex == right.pregex
, and flags == right.flags
. Otherwise it returns false.
regex_iterator::operator->
Accesses the designated match.
const match_results<BidIt> * operator->();
Remarks
The member function returns the address of the stored value match
.
regex_iterator::pointer
The type of a pointer to a match.
typedef match_results<BidIt> *pointer;
Remarks
The type is a synonym for match_results<BidIt>*
, where BidIt
is the template parameter.
regex_iterator::reference
The type of a reference to a match.
typedef match_results<BidIt>& reference;
Remarks
The type is a synonym for match_results<BidIt>&
, where BidIt
is the template parameter.
regex_iterator::regex_iterator
Constructs the iterator.
regex_iterator();
regex_iterator(BidIt first,
BidIt last,
const regex_type& re,
regex_constants::match_flag_type f = regex_constants::match_default);
Parameters
first
Beginning of sequence to match.
last
End of sequence to match.
re
Regular expression for matches.
f
Flags for matches.
Remarks
The first constructor constructs an end-of-sequence iterator. The second constructor initializes the stored value begin
with first, the stored value end
with last, the stored value pregex
with &re
, and the stored value flags
with f. It then calls regex_search(begin, end, match, *pregex, flags)
. If the search fails, the constructor sets the object to an end-of-sequence iterator.
regex_iterator::regex_type
The type of the regular expression to match.
typedef basic_regex<Elem, RXtraits> regex_type;
Remarks
The typedef is a synonym for basic_regex<Elem, RXtraits>
.
regex_iterator::value_type
The type of a match.
typedef match_results<BidIt> value_type;
Remarks
The type is a synonym for match_results<BidIt>
, where BidIt
is the template parameter.
See also
<regex>
regex_constants Class
regex_error Class
<regex> functions
regex_iterator Class
<regex> operators
regex_token_iterator Class
regex_traits Class
<regex> typedefs