- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ Regex Library - regex_iterator
Description
It is an iterator type to iterate over different matches of a same regex pattern in a sequence.
Declaration
Following is the declaration for std::regex_iterator.
emplate <class BidirectionalIterator, class charT=typename iterator_traits<BidirectionalIterator>::value_type, class traits=regex_traits<charT> > class regex_iterator;
C++11
emplate <class BidirectionalIterator, class charT=typename iterator_traits<BidirectionalIterator>::value_type, class traits=regex_traits<charT> > class regex_iterator;
C++14
emplate <class BidirectionalIterator, class charT=typename iterator_traits<BidirectionalIterator>::value_type, class traits=regex_traits<charT> > class regex_iterator;
Parameters
BidirectionalIterator − It is a bidirectional iterator type that iterates on the target sequence of characters.
charT − It is a char type.
traits − It is a regex traits type.
Return Value
It returns a string object with the resulting sequence.
Exceptions
No-noexcept − this member function never throws exceptions.
Example
In below example for std::regex_iterator.
#include <regex> #include <iterator> #include <iostream> #include <string> int main() { const std::string s = "Tutorialspoint.com india pvt ltd."; std::regex words_regex("[^\\s]+"); auto words_begin = std::sregex_iterator(s.begin(), s.end(), words_regex); auto words_end = std::sregex_iterator(); std::cout << "Found " << std::distance(words_begin, words_end) << " words:\n"; for (std::sregex_iterator i = words_begin; i != words_end; ++i) { std::smatch match = *i; std::string match_str = match.str(); std::cout << match_str << '\n'; } }
The output should be like this −
Found 4 words: Tutorialspoint.com india pvt ltd.
regex.htm
Advertisements