0

I have the following text

text = "السلام عليكم @%^ كِم مرُة قــــلتلكًة ل! لا لا آآآآآ إإإإ أأأأأenglish"

I want to remove all non-Arabic characters so I used the regular expression as

# replace all non-Arabic text
text = text.replace("[^ابتثجحخدذرزسشصضطظعغفقكنهويىؤئء]","")
print(text)

However, this did not work with me, I also tried replacing some characters [أإآ] with "ا" but it also did not work with me

text = text.replace("[أإآ]","ا")
print(text)

I tried replacing single characters such as "ة" with "ه" and it worked. But the square brackets did not work, I even tried the English letters to check if the problem is because of the Arabic text but it did not work also.

Ameera
  • 33
  • 5
  • 2
    `[^ابتثجحخدذرزسشصضطظعغفقكنهويىؤئء]` is a regex, so use it with the appropriate `re.sub` method. – Wiktor Stribiżew Jun 18 '18 at 10:10
  • Use the inbuilt re module in python to solve this. re.sub(REGX_STRING,STRING_WITH_WHICH_YOU_WANT_TO_REPLACE,STRING_FOR_WHICH_THIS_IS_APPLIED) aand the function returns the new string – Kalyan Prusty Jun 04 '19 at 08:49

0 Answers0