PySide6.QtCore.QRegularExpressionMatchIterator¶
- class QRegularExpressionMatchIterator¶
- The - QRegularExpressionMatchIteratorclass provides an iterator on the results of a global match of a- QRegularExpressionobject against a string. More…- Synopsis¶- Methods¶- def - __init__()
- def - hasNext()
- def - isValid()
- def - matchOptions()
- def - matchType()
- def - next()
- def - peekNext()
- def - swap()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - A - QRegularExpressionMatchIteratorobject is a forward only Java-like iterator; it can be obtained by calling the- globalMatch()function. A new- QRegularExpressionMatchIteratorwill 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 - QRegularExpressionMatchobject 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, - QRegularExpressionMatchIteratoroffers 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 - globalMatchin 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 - QRegularExpressionobject 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 - QRegularExpressiondocumentation for more information about the Qt regular expression classes.- __init__()¶
 - Constructs an empty, valid - QRegularExpressionMatchIteratorobject. The regular expression is set to a default-constructed one; the match type to- NoMatchand 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.- __init__(iterator)
- Parameters:
- iterator – - QRegularExpressionMatchIterator
 
 - Constructs a - QRegularExpressionMatchIteratorobject as a copy of- iterator.- See also - operator=()- hasNext()¶
- Return type:
- bool 
 
 - Returns - trueif there is at least one match result ahead of the iterator; otherwise it returns- false.- See also - isValid()¶
- Return type:
- bool 
 
 - Returns - trueif the iterator object was obtained as a result from the- globalMatch()function invoked on a valid- QRegularExpressionobject; returns- falseif the- QRegularExpressionwas invalid.- See also - matchOptions()¶
- Return type:
- Combination of - MatchOption
 
 - Returns the match options that were used to get this - QRegularExpressionMatchIteratorobject, that is, the match options that were passed to- globalMatch().- See also - Returns the match type that was used to get this - QRegularExpressionMatchIteratorobject, that is, the match type that was passed to- globalMatch().- 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. - 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. - regularExpression()¶
- Return type:
 
 - Returns the - QRegularExpressionobject whose globalMatch() function returned this object.- See also - swap(other)¶
- Parameters:
- other – - QRegularExpressionMatchIterator
 
 - Swaps this iterator with - other. This operation is very fast and never fails.