Search code examples
pythonexpressionarabicright-to-left

How to reverse punctuation marks using regular expression in python?


I need a regular expression in python in a format like this one to reverse the Arabic punctuation marks from the right start of the word to the left end of it like "!, ‏‎؟‎, ., ‏‎،‎," and to reverse "-, ...,".

file_content = re.sub(r'^ +', r'', file_content, flags=re.MULTILINE) 

Example:

؟هل أنت بخير

I need it to be:

هل أنت بخير؟

Solution

  • Try:

    file_content = re.sub(ur'^(.*)(؟)$', r'$2$1', file_content, flags=re.MULTILINE)