<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Simple regexes like that one will match all sequences of characters found; if you want to find those character as a single "word", you will need to use word boundaries.</div><div><br></div><div>Change the pattern init to this and it works (at least, according to the string you gave):<br><br></div><div><font face="monospace, monospace">pattern = QtCore.QRegExp(r'\b{}\b'.<wbr>format(self.lineEdit.text()))</font><br></div><div><br></div><div>Have a look at this, too: <a href="https://stackoverflow.com/questions/40731058/regex-match-arabic-keyword" target="_blank">https://stackoverflow.<wbr>com/questions/40731058/regex-<wbr>match-arabic-keyword</a><br></div><div><br>As a side note, forgive my bluntness, but you might want to read some more documentation about regex and right-to-left languages practices.</div><div>The latest questions you asked were not python nor qt related at all, and, as you might understand, most of the people on this mailing list don't even know how arabic language works; a bit of context might be useful, so that even people not experienced with those language might help too.</div><div><br>Also, try to simplify examples by limiting code to what is really related to your issue: those geometry, font and widget settings won't help anyone reading your code. The same example could have been written in less than half lines, and would have been much more readable: easier to read is easier to understand and easier to help.<br>Finally, avoid mixing the way you import modules. You should import from the main module _OR_ from the submodules. While it doesn't change much in terms of computation, it decreases the possibility of bugs and improves readibility, which is better for everybody reading your code, including you :-)</div><div><br></div><div>Maurizio</div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-09-01 20:33 GMT+02:00 Maziar Parsijani <span dir="ltr"><<a href="mailto:maziar.parsijani@gmail.com" target="_blank">maziar.parsijani@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><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="background-color:rgb(255,255,255);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="m_-3820615639630079966m_-5172197483062635484gmail-"> </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="background-color:rgb(255,255,255);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(QtCo<wbr>re.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">"l<wbr>ineEdit"</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(Qt<wbr>Core.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"><wbr>"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<wbr>(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(fon<wbr>t)<br>        <span style="color:rgb(148,85,141)">self</span>.SearchResults.setToolTipD<wbr>uration(<span style="color:rgb(0,0,255)">0</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.SearchResults.setReadOnly<wbr>(<span style="color:rgb(0,0,128);font-weight:bold">True</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.SearchResults.setAutoForm<wbr>atting(QtWidgets.QTextEdit.<wbr>AutoAll)<br>        <span style="color:rgb(148,85,141)">self</span>.SearchResults.setObjectNa<wbr>me(<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.connectSlot<wbr>sByName(<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(<wbr>)<br>            format = QtGui.QTextCharFormat()<br>            format.setForeground(QtGui.QBr<wbr>ush(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.tex<wbr>t())<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>.SearchResul<wbr>ts.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.QTex<wbr>tCursor.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>.SearchResul<wbr>ts.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><wbr>.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.transl<wbr>ate<br>        <span style="color:rgb(148,85,141)">self</span>.setWindowTitle(_translate<wbr>(<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(_trans<wbr>late(<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.connec<wbr>t(<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_())<br></pre></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<br>______________________________<wbr>_________________<br>
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.riverbankcomputing<wbr>.com/mailman/listinfo/pyqt</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_-3820615639630079966gmail_signature" data-smartmail="gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>
</div></div>