Regex: How to turn more words in the line as if they were seen in the mirror?

Mirrors Actually Flip the Letters in a Word? Or, how to turn more words in the line as if they were seen in the mirror?

For example:

At the Olympics you run not only for yourself, but for all people.

After using a regex formula, the output should be:

Ta eht scipmylO uoy nur ton ylno rof flesruoy, tub rof lla elpoep.

I made a regex formula, but is not working:

FIND: ([a-z])|([A-Z])\1\2

REPLACE BY: \2\1

OR

FIND: ([^\s])|([^\s])

REPLACE BY: \2\1


This can't be done with regex alone, you have to run a pythonSCript.

If it is not yet installed, follow this guide

  • Create a script (Plugins >> PythonScript >> New Script)
  • Copy this code and save the file (for example reverseWord.py):
import re

def reverseWord(match):
    str = match.group(1)
    return ''.join(reversed(str))

editor.rereplace('(\w+)', reverseWord)
  • Open the file you want to modify
  • Run the script (Plugins >> PythonScript >> Scripts >> reverseWord)
  • Done

enter image description here