QRegularExpressionMatchIterator Class

The QRegularExpressionMatchIterator class provides an iterator on the results of a global match of a QRegularExpression object against a string. More...

Header: #include <QRegularExpressionMatchIterator>
qmake: QT += core
Since: Qt 5.0

This class was introduced in Qt 5.0.

Note: All functions in this class are reentrant.

Detailed Description

A QRegularExpressionMatchIterator object is a forward only Java-like iterator; it can be obtained by calling the QRegularExpression::globalMatch() function. A new QRegularExpressionMatchIterator will be positioned before the first result. You can then call the hasNext() function to check if there are more results available; if so, the next() function will return the next result and advance the iterator.

Each result is a QRegularExpressionMatch object holding all the information for that result (including captured substrings).

For instance:

 // extracts the words
 QRegularExpression re("(\\w+)");
 QString subject("the quick fox");
 QRegularExpressionMatchIterator i = re.globalMatch(subject);
 while (i.hasNext()) {
     QRegularExpressionMatch match = i.next();
     // ...
 }

Moreover, QRegularExpressionMatchIterator offers a peekNext() function to get the next result without advancing the iterator.

You can retrieve the QRegularExpression object the subject string was matched against by calling the regularExpression() function; the match type and the match options are available as well by calling the matchType() and the matchOptions() respectively.

Please refer to the QRegularExpression documentation for more information about the Qt regular expression classes.

See also QRegularExpression and QRegularExpressionMatch.