std::regex_iterator

From cppreference.com
Jump to: navigation, search
template<

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

> class regex_iterator
(since C++11)

Several specializations for common character sequence types are defined:

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

[edit] Example

#include <regex>
#include <iterator>
#include <iostream>
 
int main()
{
    const std::string text = "Quick brown fox.";
 
    auto begin_it = std::sregex_iterator();
    auto end_it = std::sregex_iterator(text.begin(), text.end(), std::regex("[^\\s]+"));
 
    std::cout << "The number of words is " 
              << std::distance(begin_it, end_it) << count << '\n';
}

Output:

The number of words is 3
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox