<div dir="ltr">Thanks for your pro and advance answer.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Aug 29, 2018 at 10:07 AM Zachary Scheuren <<a href="mailto:angryjaga@gmail.com">angryjaga@gmail.com</a>> wrote:<br></div><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">Yes, that's what I was afraid of. You lose the index when you strip the marks so you need to keep track of them somehow. One way is to split on spaces and track it that way. Something like this with PyQt5. You'll need to fill in your pieces, but the main idea is here:</div><div dir="ltr"><br></div><div dir="ltr"># setup your QApplication and QTextEdit, etc.<br><div>from pyarabic import araby</div><div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">from PyQt5.QtGui import QTextCharFormat<br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">from PyQt5.QtGui import QTextCursor</div><div><br></div>textedit = your QTextEdit<br><div>text = the source text</div><div>text2 = araby.strip_tashkeel(text)</div></div><div>search_string = '<span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">السماء</span>'</div><div>matches = []</div><div><br></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"># to be more accurate about the match you can use re.finditer() instead of just "if search_string in" to get the start index, </span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"># but then you should track that as well as the list index so you can be more accurate later. </span>this is just a quick proof of concept so I didn't go all the way</div><div>for i, c in enumerate(text2.split()):<br></div><div>    if <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">search_string</span> in c:</div><div>        matches.append(i)</div><div><br></div><div># Now use the match indices to highlight the original text</div><div>cursor = textedit.textCursor()</div><div>highlight_color = QColor()  # whatever color you want<br></div><div>fmt = QTextCharFormat()<br></div><div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">fmt.setBackground(highlight_color)<br></div><br></div><div>for match_index in matches:</div><div>    start = len(' '.join(text.split()[0:match_index])) + 1<br></div><div>    end = len(' '.join(text.split()[0:match_index + 1]))<br class="m_5873032231457722514m_6369581018493898656gmail-Apple-interchange-newline"></div><div>    cursor.setPosition(start, QTextCursor.MoveAnchor)</div><div>    cursor.setPosition(end, QTextCursor.KeepAnchor)</div><div>    cursor.setCharFormat(fmt)</div><div><br></div><div>This works, but it can highlight some parts that aren't really part of the match. To avoid that you could check the index offset within each matched item in the list to make sure you get the right start index. It's all possible. Just takes some more code. I hope this helps get you closer. </div><div><br></div><div><br></div></div></div></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 28, 2018 at 12:57 AM, Maziar Parsijani <span dir="ltr"><<a href="mailto:maziar.parsijani@gmail.com" target="_blank">maziar.parsijani@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi<span name="Zachary Scheuren" class="m_5873032231457722514m_8558139098989795839gmail-gD"> Zachary Scheuren<br>Thanks a lot for your answer .The reason I have Email PYQT is that I use its widgets and I forgot to say that I use Qtextedit.And for more detail I can say that I found that pyarabic library before and as you said I can remove marks with its</span><span style="color:rgb(128,128,128);font-style:italic"> strip_tashkeel(text)</span><span name="Zachary Scheuren" class="m_5873032231457722514m_8558139098989795839gmail-gD"> function ,But if you take a look at below example I think you will find what I want to do.And I can refer you to <a href="http://tanzil.net" target="_blank">http://tanzil.net</a> here if you search for "</span><span name="Zachary Scheuren" class="m_5873032231457722514m_8558139098989795839gmail-gD">السماء" it will find and highlight "</span><span name="Zachary Scheuren" class="m_5873032231457722514m_8558139098989795839gmail-gD"><span id="m_5873032231457722514m_8558139098989795839gmail-2-19" class="m_5873032231457722514m_8558139098989795839gmail-aya m_5873032231457722514m_8558139098989795839gmail-selected"><span class="m_5873032231457722514m_8558139098989795839gmail-aya-wrapper" style="background-color:transparent"><span class="m_5873032231457722514m_8558139098989795839gmail-ayaText">ٱلسَّمَآءِ" I want to know if its possible in python?I use sqlite database and I could find the results like this but I can not highlight them.<br></span></span></span></span>Example :<br>search for :" السماء "<br>but I want to show Quranuthmani and find :" ٱلسَّمَآءِ" in it and highlight them.<br>I
 can find them with no problem cause of using sqlite database table with
 different Quran text But the problem is highlighting them cause of 
using regex <br>and " السماء " ," ٱلسَّمَآءِ" are not the same so I can not highlight them.<br>Please accept my apologizes for asking my question before your permission . </div><div class="m_5873032231457722514HOEnZb"><div class="m_5873032231457722514h5"><br><div class="gmail_quote"><div dir="ltr">On Mon, Aug 27, 2018 at 10:14 AM Zachary Scheuren <<a href="mailto:angryjaga@gmail.com" target="_blank">angryjaga@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This isn't really a PyQt question. You can do all that in basic Python, but it can help if you have something like the pyarabic library. With that you can strip out the vocalization before comparing strings. You also need to consider all the possible Alefs like in str1 you have Alef with Wasla, but str2 only has Alef. pyarabic can also help there with araby.ALEFAT which is a list of all possible Alefs with marks. You need to manually check that because Alef with Wasla has no Unicode decomposition and the wasla isn't encoded as a separate mark. There have been Unicode proposals for that, but nothing has happened so far. Anyway, I did a quick little test with your strings...<div><div><div><br></div><div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">import re</div></div><div>from pyarabic import araby</div><div>str3_nomarks = araby.separate(str3)[0]  # strips all diacritics<br></div><div>for c in araby.ALEFAT:  # replace any Alef with a mark by base Alef</div><div>    str3_nomarks = str3_nomarks.replace(c, araby.ALEF)</div><div><br></div><div>re.findall(str2, str3_nomarks)</div><div><br></div><div>Something like that will get you matches, but if you need to track the position in a string you'll have to do some more work since dropping the diacritics will throw off the index. </div><div><br></div><div><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 22, 2018 at 12:43 AM, Maziar Parsijani <span dir="ltr"><<a href="mailto:maziar.parsijani@gmail.com" target="_blank">maziar.parsijani@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>Hi<br></div>I have some Arabic strings in mt database now I want to if I search like this :<br> <br></div>  str1 = "ٱلْمُفْلِحُونَ"<br></div>  str2 = "المفلحون"<br></div>as you can see str1 is the same as str2 but in Arabic text str1 has more alphabetical characters.<br></div>Is there anyway to search str2 but I could find both of them in a string like :<br></div> str3 = " المفلحون ٱلْمُفْلِحُونَ ٱلنَّاسُ المفلحون ٱلْمُفْلِحُونَ المفلحون ٱلنَّاسُ المفلحون ٱلنَّاسُ "</div>
<br>_______________________________________________<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.com/mailman/listinfo/pyqt</a><br></blockquote></div><br></div>
</blockquote></div>
</div></div></blockquote></div><br></div>
</blockquote></div>