std::regex_iterator
From cppreference.com
| C++ Reference | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Regular expressions library | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template< class BidirectionalIterator, |
(since C++11) | |
| This section is incomplete |
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> |
| This section is incomplete |
[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