Iterating Over Pattern Matches
RWURegexMatchIterator provides a convenient interface for finding all successive matches of a particular regular expression pattern in a string. RWURegexMatchIterator is a forward iterator, allowing forward searches over the specified string using pre-increment and post-increment operators. For example:
RWURegularExpression r(pattern);
for (RWURegexMatchIterator iter(r, str);
iter != RWURegexMatchIterator(); ++iter) {
std::cout << "Match at offset: " << iter->getStart()
<< std::endl;
}
Note the use of the default
RWURegexMatchIterator constructor, which creates an invalid iterator that can be used to test for the end-of-iteration condition.
As with many iterators, changing the item(s) being iterated over invalidates the match iterator. If the regular expression pattern or search string used by an
RWURegexMatchIterator is changed, then the match iterator is invalidated.