QRegularExpressionMatchIterator¶
The QRegularExpressionMatchIterator
class provides an iterator on the results of a global match of a QRegularExpression
object against a string. More…
Synopsis¶
Functions¶
def
hasNext
()def
isValid
()def
matchOptions
()def
matchType
()def
next
()def
peekNext
()def
regularExpression
()def
swap
(other)
Detailed Description¶
A QRegularExpressionMatchIterator
object is a forward only Java-like iterator; it can be obtained by calling the 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 re = QRegularExpression("(\\w+)") subject = QString("the quick fox") i = re.globalMatch(subject) while i.hasNext(): match = i.next() # ...
Moreover, QRegularExpressionMatchIterator
offers a peekNext()
function to get the next result without advancing the iterator.
Starting with Qt 6.0, it is also possible to simply use the result of globalMatch
in a range-based for loop, for instance like this:
# using a raw string literal, R"(raw_characters)", to be able to use "\w" # without having to escape the backslash as "\\w" re = QRegularExpression(R"(\w+)") subject = QString("the quick fox") for match in re.globalMatch(subject): # ...
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.
- class PySide6.QtCore.QRegularExpressionMatchIterator¶
PySide6.QtCore.QRegularExpressionMatchIterator(iterator)
- Parameters
Constructs an empty, valid QRegularExpressionMatchIterator
object. The regular expression is set to a default-constructed one; the match type to NoMatch
and the match options to NoMatchOption
.
Invoking the hasNext()
member function on the constructed object will return false, as the iterator is not iterating on a valid sequence of matches.
- PySide6.QtCore.QRegularExpressionMatchIterator.hasNext()¶
- Return type
bool
Returns true
if there is at least one match result ahead of the iterator; otherwise it returns false
.
See also
- PySide6.QtCore.QRegularExpressionMatchIterator.isValid()¶
- Return type
bool
Returns true
if the iterator object was obtained as a result from the globalMatch()
function invoked on a valid QRegularExpression
object; returns false
if the QRegularExpression
was invalid.
See also
- PySide6.QtCore.QRegularExpressionMatchIterator.matchOptions()¶
- Return type
MatchOptions
Returns the match options that were used to get this QRegularExpressionMatchIterator
object, that is, the match options that were passed to globalMatch()
.
See also
Returns the match type that was used to get this QRegularExpressionMatchIterator
object, that is, the match type that was passed to globalMatch()
.
- PySide6.QtCore.QRegularExpressionMatchIterator.next()¶
- Return type
Returns the next match result and advances the iterator by one position.
Note
Calling this function when the iterator is at the end of the result set leads to undefined results.
- PySide6.QtCore.QRegularExpressionMatchIterator.peekNext()¶
- Return type
Returns the next match result without moving the iterator.
Note
Calling this function when the iterator is at the end of the result set leads to undefined results.
- PySide6.QtCore.QRegularExpressionMatchIterator.regularExpression()¶
- Return type
Returns the QRegularExpression
object whose globalMatch() function returned this object.
See also
- PySide6.QtCore.QRegularExpressionMatchIterator.swap(other)¶
- Parameters
Swaps the iterator other
with this iterator object. This operation is very fast and never fails.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.