<div dir="ltr"><div dir="ltr">I want to select 2 "<span style="color:rgb(0,128,128);font-weight:bold">قَالَ</span>" in m = "<span style="color:rgb(0,128,128);font-weight:bold">قَالَتْ قَالَ فَقَالُو</span><span style="color:rgb(0,128,128);font-weight:bold;font-family:"Amiri Quran Colored"">ا۟</span><span style="color:rgb(0,128,128);font-weight:bold"> قَالُو</span><span style="color:rgb(0,128,128);font-weight:bold;font-family:"Amiri Quran Colored"">ا۟</span><span style="color:rgb(0,128,128);font-weight:bold"> قَالَ قَالُوٓ</span><span style="color:rgb(0,128,128);font-weight:bold;font-family:"Amiri Quran Colored"">ا۟</span><span style="color:rgb(0,128,128);font-weight:bold"> قَالَتَا </span><span style="color:rgb(0,128,128);font-weight:bold;font-family:Aldhabi">ٱ</span><span style="color:rgb(0,128,128);font-weight:bold">لْقَالِينَ</span>  " but with the below code it selects all words which contains " "<span style="color:rgb(0,128,128);font-weight:bold">قَالَ</span>"  <br></div><div>Now what is the problem here?<br></div><div>I have to put spaces before and after pattern1 for such thing but it doesn't work for me.<br><pre style="white-space:pre-wrap;color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:9.1pt">pattern1 = <span style="color:rgb(0,128,128);font-weight:bold">" {0} "</span>.format(<span style="color:rgb(148,85,141)">self</span>.lineEdit.text())<span class="gmail-m_-5775024115290636932gmail-"> </span></pre></div><div dir="ltr"><span style="color:rgb(0,128,128);font-weight:bold"></span></div><div><span style="color:rgb(0,128,128);font-weight:bold"><br></span></div><div dir="ltr"><pre style="white-space:pre-wrap;color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:9.1pt"><span style="color:rgb(0,0,128);font-weight:bold">from </span>PyQt5 <span style="color:rgb(0,0,128);font-weight:bold">import </span>QtCore, QtGui, QtWidgets<br><span style="color:rgb(0,0,128);font-weight:bold">from </span>PyQt5.QtWidgets <span style="color:rgb(0,0,128);font-weight:bold">import </span>QApplication, QTextEdit<br><span style="color:rgb(0,0,128);font-weight:bold">from </span>PyQt5.QtGui <span style="color:rgb(0,0,128);font-weight:bold">import </span>QTextDocument, QTextDocumentFragment<br><span style="color:rgb(0,0,128);font-weight:bold">from </span>PyQt5 <span style="color:rgb(0,0,128);font-weight:bold">import </span>QtCore, QtGui, QtWidgets<br><span style="color:rgb(0,0,128);font-weight:bold">import </span>sys<br><span style="color:rgb(0,0,128);font-weight:bold">from </span>PyQt5.QtWidgets <span style="color:rgb(0,0,128);font-weight:bold">import </span>QDialog, QApplication<br><span style="color:rgb(0,0,128);font-weight:bold">class </span>AppWindow(QDialog):<br>    <span style="color:rgb(0,0,128);font-weight:bold">def </span><span style="color:rgb(178,0,178)">__init__</span>(<span style="color:rgb(148,85,141)">self</span>):<br>        <span style="color:rgb(0,0,128)">super</span>().<span style="color:rgb(178,0,178)">__init__</span>()<br>        <span style="color:rgb(148,85,141)">self</span>.setObjectName(<span style="color:rgb(0,128,128);font-weight:bold">"Dialog"</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.resize(<span style="color:rgb(0,0,255)">800</span>, <span style="color:rgb(0,0,255)">600</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.lineEdit = QtWidgets.QLineEdit(<span style="color:rgb(148,85,141)">self</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.lineEdit.setGeometry(QtCore.QRect(<span style="color:rgb(0,0,255)">70</span>, <span style="color:rgb(0,0,255)">70</span>, <span style="color:rgb(0,0,255)">211</span>, <span style="color:rgb(0,0,255)">21</span>))<br>        <span style="color:rgb(148,85,141)">self</span>.lineEdit.setObjectName(<span style="color:rgb(0,128,128);font-weight:bold">"lineEdit"</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.pushButton = QtWidgets.QPushButton(<span style="color:rgb(148,85,141)">self</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.pushButton.setGeometry(QtCore.QRect(<span style="color:rgb(0,0,255)">130</span>, <span style="color:rgb(0,0,255)">110</span>, <span style="color:rgb(0,0,255)">83</span>, <span style="color:rgb(0,0,255)">28</span>))<br>        <span style="color:rgb(148,85,141)">self</span>.pushButton.setObjectName(<span style="color:rgb(0,128,128);font-weight:bold">"pushButton"</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.SearchResults = QtWidgets.QTextEdit(<span style="color:rgb(148,85,141)">self</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.SearchResults.setGeometry(QtCore.QRect(<span style="color:rgb(0,0,255)">130</span>, <span style="color:rgb(0,0,255)">140</span>, <span style="color:rgb(0,0,255)">500</span>, <span style="color:rgb(0,0,255)">400</span>))<br>        font = QtGui.QFont()<br>        font.setFamily(<span style="color:rgb(0,128,128);font-weight:bold">"Amiri"</span>)<br>        font.setPointSize(<span style="color:rgb(0,0,255)">12</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.SearchResults.setFont(font)<br>        <span style="color:rgb(148,85,141)">self</span>.SearchResults.setToolTipDuration(<span style="color:rgb(0,0,255)">0</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.SearchResults.setReadOnly(<span style="color:rgb(0,0,128);font-weight:bold">True</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.SearchResults.setAutoFormatting(QtWidgets.QTextEdit.AutoAll)<br>        <span style="color:rgb(148,85,141)">self</span>.SearchResults.setObjectName(<span style="color:rgb(0,128,128);font-weight:bold">"SearchResults"</span>)<br><br>        <span style="color:rgb(148,85,141)">self</span>.retranslateUi(<span style="color:rgb(148,85,141)">self</span>)<br>        QtCore.QMetaObject.connectSlotsByName(<span style="color:rgb(148,85,141)">self</span>)<br>    <span style="color:rgb(0,0,128);font-weight:bold">def </span>find1(<span style="color:rgb(148,85,141)">self</span>):<br>            m = <span style="color:rgb(0,128,128);font-weight:bold">"  قَالَتْ  قَالَ فَقَالُو</span><span style="color:rgb(0,128,128);font-weight:bold;font-family:"Amiri Quran Colored"">ا۟</span><span style="color:rgb(0,128,128);font-weight:bold"> قَالُو</span><span style="color:rgb(0,128,128);font-weight:bold;font-family:"Amiri Quran Colored"">ا۟</span><span style="color:rgb(0,128,128);font-weight:bold"> قَالَ  قَالُوٓ</span><span style="color:rgb(0,128,128);font-weight:bold;font-family:"Amiri Quran Colored"">ا۟</span><span style="color:rgb(0,128,128);font-weight:bold"> قَالَتَا  </span><span style="color:rgb(0,128,128);font-weight:bold;font-family:Aldhabi">ٱ</span><span style="color:rgb(0,128,128);font-weight:bold">لْقَالِينَ    "<br></span><span style="color:rgb(0,128,128);font-weight:bold">            </span><span style="color:rgb(148,85,141)">self</span>.SearchResults.append(<span style="color:rgb(0,128,128);font-weight:bold">'{0} '</span>.format(m))<br><br><br>            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><br>            pattern1 = <span style="color:rgb(0,128,128);font-weight:bold">"{0}"</span>.format(<span style="color:rgb(148,85,141)">self</span>.lineEdit.text())<br>            regex = QtCore.QRegExp(pattern1)<br>            pos = <span style="color:rgb(0,0,255)">0<br></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>            tedad = <span style="color:rgb(0,0,255)">0<br></span><span style="color:rgb(0,0,255)">            </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>                <span style="color:rgb(0,0,128);font-weight:bold">if </span>regex.isValid():<br>                    tedad += <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">            </span><span style="color:rgb(128,128,128)">nmayesh </span>= (<span style="color:rgb(0,128,128);font-weight:bold">"{}"</span>.format(tedad))<br>            <span style="color:rgb(148,85,141)">self</span>.SearchResults.append(<span style="color:rgb(0,128,128);font-weight:bold">"{}"</span>.format(tedad))<br><br>    <span style="color:rgb(0,0,128);font-weight:bold">def </span>retranslateUi(<span style="color:rgb(148,85,141)">self</span>, <span style="color:rgb(128,128,128)">Dialog</span>):<br>        _translate = QtCore.QCoreApplication.translate<br>        <span style="color:rgb(148,85,141)">self</span>.setWindowTitle(_translate(<span style="color:rgb(0,128,128);font-weight:bold">"Dialog"</span>, <span style="color:rgb(0,128,128);font-weight:bold">"Dialog"</span>))<br>        <span style="color:rgb(148,85,141)">self</span>.pushButton.setText(_translate(<span style="color:rgb(0,128,128);font-weight:bold">"Dialog"</span>, <span style="color:rgb(0,128,128);font-weight:bold">"PushButton"</span>))<br>        <span style="color:rgb(148,85,141)">self</span>.pushButton.clicked.connect(<span style="color:rgb(148,85,141)">self</span>.find1)<br><br>app = QApplication(sys.argv)<br>w = AppWindow()<br>w.show()<br>sys.exit(app.exec_())</pre></div></div>