std::regex_iterator<BidirIt,CharT,Traits>::regex_iterator
From cppreference.com
 
 
 < cpp | regex | regex iterator 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Text processing library 
   
 Regular expressions library (C++11)
 Formatting library (C++20)
Regular expressions library 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Classes
(C++11)
(C++11)
(C++11)
 Algorithms
(C++11)
(C++11)
(C++11)
 Iterators
(C++11)
(C++11)
 Exceptions
(C++11)
 Traits
(C++11)
 Constants
(C++11)
(C++11)
(C++11)
 Regex Grammar
(C++11)
std::regex_iterator 
 
 
 Member functions
regex_iterator::regex_iterator
 Comparisons
(until C++20)
 Observers
 Modifiers
regex_iterator();
 (1) 
 (since C++11) 
regex_iterator( BidirIt a, BidirIt b,
 (2) 
 (since C++11) 
                const regex_type& re,
                std::regex_constants::match_flag_type m =
regex_iterator( const regex_iterator& );
 (3) 
 (since C++11) 
regex_iterator( BidirIt, BidirIt,
 (4) 
 (since C++11) 
                const regex_type&&,
                std::regex_constants::match_flag_type =
Constructs a new regex_iterator:
1) Default constructor. Constructs an end-of-sequence iterator.
2) Constructs a 
regex_iterator from the sequence of characters [a, b), the regular expression re, and a flag m that governs matching behavior. This constructor performs an initial call to std::regex_search  with this data. If the result of this initial call is false, *this is set to an end-of-sequence iterator.3) Copies a 
regex_iterator.4) The overload (2) is not allowed to be called with a temporary regex, since the returned iterator would be immediately invalidated.
[edit] Parameters
 a
 -
 LegacyBidirectionalIterator to the beginning of the target character sequence
 b
 -
 LegacyBidirectionalIterator to the end of the target character sequence
 re
 -
 regular expression used to search the target character sequence
 m
 -
 flags that govern the behavior of re
[edit] Example
Run this code
#include <iostream> #include <regex> #include <string_view> int main() { constexpr std::string_view str{R"( #ONE: *p = &Mass; #Two: MOV %rd, 42 )"}; const std::regex re("[a-w]"); // create regex_iterator, overload (2) auto it = std::regex_iterator <std::string_view::iterator> { str.cbegin(), str.cend(), re // re is lvalue; if an immediate expression was used // instead, e.g. std::regex{"[a-z]"}, this would // produce an error since overload (4) is deleted }; for (decltype(it) last /* overload (1) */; it != last; ++it) std::cout << (*it).str(); std::cout << '\n'; }
Output:
password
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior | 
|---|---|---|---|
| LWG 2332 | C++11 | a regex_iteratorconstructed from a temporarybasic_regexbecame invalid immediately | such construction is disallowed via a deleted overload |