コード例 #1
0
 def testMatchIterator(self):
     re = QRegularExpression('(\w+)')
     self.assertTrue(re.isValid())
     count = 0
     it = re.globalMatch('word1 word2 word3')
     while it.hasNext():
         it.next()
         count = count + 1
     self.assertEqual(count, 3)
コード例 #2
0
    def highlightBlock(self, text):
        myClassFormat = QTextCharFormat()
        myClassFormat.setFontWeight(QFont.Bold)

        expression = QRegularExpression(self.pattern)
        i = expression.globalMatch(text)

        while i.hasNext():
            match = i.next()
            myClassFormat.setForeground(
                self.tagColorMap[match.capturedTexts()[0]])
            self.setFormat(match.capturedStart(), match.capturedLength(),
                           myClassFormat)