PyQt5 QRegExp问题
怎么回事,查找只匹配第一个空格前的部分,我希望不用正则全部匹配?
def btnfind_fun(self): pattern = self.codeline.text()
if len(pattern)>0 and pattern!=' ' :
cursor = self.CodetextEdit.textCursor()
# Setup the desired format for matches
format = QtGui.QTextCharFormat()
format.setBackground(QtGui.QBrush(QtGui.QColor("red")))
# Setup the regex engine
regex = QRegExp(pattern,QtCore.Qt.CaseInsensitive)
# Process the displayed document
pos = 0
index = regex.indexIn(self.CodetextEdit.toPlainText(), pos)
while (index != -1):
# Select the matched text and apply the desired format
cursor.setPosition(index)
cursor.movePosition(QtGui.QTextCursor.EndOfWord, 1)
cursor.mergeCharFormat(format)
# Move to the next match
pos = index + regex.matchedLength()
index = regex.indexIn(self.CodetextEdit.toPlainText(), pos)
self.CodetextEdit.moveCursor(pos)![image.jpg](/img/bVbRYyx)
另外,如何在着色前清除上次的着色
以上是 PyQt5 QRegExp问题 的全部内容, 来源链接: utcz.com/a/158334.html