<div dir="ltr"><div>Hi<br></div>I use the below code to search in qtextedit to match a word.Are there any better Idea.<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">    cursor = <span style="color:rgb(148,85,141)">self</span>.SearchResults.textCursor()<br>    format = QtGui.QTextCharFormat()<br>    format.setForeground(QtGui.QBrush(QtGui.QColor(<span style="color:rgb(0,128,128);font-weight:bold">"red"</span>)))<br>    <span style="color:rgb(148,85,141)">self</span>.lineEdit.backspace()<br>    pattern = <span style="color:rgb(148,85,141)">self</span>.lineEdit.text()<br>    regex = QtCore.QRegExp(pattern)<br>    pos = <span style="color:rgb(0,0,255)">0</span><br><span style="color:rgb(0,0,255)"></span><span style="color:rgb(0,0,255)">    </span>index = regex.indexIn(<span style="color:rgb(148,85,141)">self</span>.SearchResults.toPlainText(), pos)<br>    <span style="color:rgb(128,128,128);font-style:italic">#Tedad = 0</span><br><span style="color:rgb(128,128,128);font-style:italic"></span><span style="color:rgb(128,128,128);font-style:italic">    </span><span style="color:rgb(0,0,128);font-weight:bold">while </span>(index != -<span style="color:rgb(0,0,255)">1</span>):<br>        cursor.setPosition(index)<br>        cursor.movePosition(QtGui.QTextCursor.WordLeft,QtGui.QTextCursor.KeepAnchor)<br>        cursor.mergeCharFormat(format)<br>        pos = index + regex.matchedLength()<br>        index = regex.indexIn(<span style="color:rgb(148,85,141)">self</span>.SearchResults.toPlainText(), pos)<br></blockquote></blockquote></blockquote></blockquote><div>For example I need it to detect white spaces(" ")and match them too.<br></div><div> <br></div><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:9.1pt"><br></pre></div>