- class QRegularExpressionMatchIterator#
- QRegularExpressionMatchIterator类提供对字符串全局匹配- QRegularExpression对象的迭代器。更多...- 概要#- 方法#- def - __init__()
- def - hasNext()
- def - isValid()
- def - matchOptions()
- def - matchType()
- def - next()
- def - peekNext()
- 定义 - swap()
 - 注意 - 本文档可能包含从C++到Python自动翻译的片段。我们始终欢迎对片段翻译的贡献。如果您发现翻译存在问题,也可以通过在https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们 - 详细描述#- 警告 - 本节包含自动从C++翻译到Python的片段,可能包含错误。 - QRegularExpressionMatchIterator对象是一个单向Java样式的迭代器;可以通过调用- globalMatch()函数来获取。一个新的- QRegularExpressionMatchIterator将被定位在第一个结果之前。然后,您可以调用- hasNext()函数来检查是否有更多的结果可用;如果有,则- next()函数将返回下一个结果并向前移动迭代器。- 每个结果都是一个 - QRegularExpressionMatch对象,其中包含有关该结果的全部信息(包括捕获的子串)。- 例如 - # extracts the words re = QRegularExpression("(\\w+)") subject = QString("the quick fox") i = re.globalMatch(subject) while i.hasNext(): match = i.next() # ... - 此外, - QRegularExpressionMatchIterator提供了一个- peekNext()函数来获取下一个结果,但不移动迭代器。- 从Qt 6.0开始,也可以在基于范围的for循环中简单地使用 - globalMatch的结果,例如- # 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): # ... - 您可以通过调用 - regularExpression()函数来检索主题字符串所匹配的- QRegularExpression对象;通过调用- matchType()和- matchOptions()分别获得匹配类型和匹配选项。- 请参阅有关 Qt 正则表达式类的更多信息,请参阅 - QRegularExpression文档。- __init__()#
 - 创建一个空的、有效的 - QRegularExpressionMatchIterator对象。正则表达式设置为默认构造的;匹配类型设置为- NoMatch,匹配选项设置为- NoMatchOption。- 在构造的对象上调用 - hasNext()成员函数将返回 false,因为迭代器未在有效的匹配序列上迭代。- __init__(iterator)
- 参数)
- iterator – - QRegularExpressionMatchIterator
 
 - 将 - iterator构造为一个- QRegularExpressionMatchIterator对象的副本。- 另见 - operator=()- hasNext()#
- 返回类型)
- bool 
 
 - 如果迭代器之前至少有一个匹配结果,则返回 - true;否则返回- false。- 另见 - isValid()#
- 返回类型)
- bool 
 
 - 如果迭代器对象是从对有效 - QRegularExpression对象调用- globalMatch()函数得到的结果,则返回- true;如果- QRegularExpression无效,则返回- false。- matchOptions()#
- 返回类型)
- MatchOption的组合
 
 - 返回用于获取此 - QRegularExpressionMatchIterator对象的匹配选项,即传递给- globalMatch()的匹配选项。- matchType()#
- 返回类型)
 
 - 返回用于获取此 - QRegularExpressionMatchIterator对象的匹配类型,即传递给- globalMatch()的匹配类型。- 返回下一个匹配结果并将迭代器向前移动一个位置。 - 注意 - 当迭代器位于结果集的末尾时调用此函数会导致未定义的结果。 - 返回下一个匹配结果而不会移动迭代器。 - 注意 - 当迭代器位于结果集的末尾时调用此函数会导致未定义的结果。 - 返回其 - globalMatch函数返回此对象的- QRegularExpression对象。- swap(other)
- 参数)
- other – - QRegularExpressionMatchIterator
 
 - 交换迭代器 - other与此迭代器对象。此操作非常快速且永远不会失败。