Text Transform

Text reverser

What to do

Transformed in your browser Β· nothing is uploaded

Local Β· code-point aware; multi-code-point emoji still reorder

Three reversals, and they are genuinely different operations: the characters, the order of the words, or the order of the lines. The character reversal iterates by code point rather than by UTF-16 unit, so a single emoji or a CJK character comes back whole instead of in pieces. Anything assembled from several code points is still reordered: a flag is two of them, and πŸ‡³πŸ‡± reversed is πŸ‡±πŸ‡³.

How to use the text reverser

1 Paste the text.
2 Choose characters, word order or line order. The same input gives three different results.
3 To reverse the letters inside each word but keep the words where they are, reverse the characters and then reverse the word order.
4 Copy the result, or save it as a text file.

Reversing characters is where an implementation detail becomes visible. Doing it naively splits a string into UTF-16 code units, which breaks any character outside the basic range; emoji and many CJK characters come apart into meaningless fragments. This iterates by code point instead, so any single character survives intact. What no reversal can preserve is a sequence built from several code points, because reordering them is the whole operation: a flag is two regional-indicator code points, so πŸ‡³πŸ‡± comes back as πŸ‡±πŸ‡³, which is a different flag; a skin-tone modifier follows its base emoji, so πŸ‘πŸ½ comes back as the modifier followed by a bare thumb; and a family joined with zero-width joiners reverses into its members in the opposite order. Combining marks are the same problem in miniature β€” an accent stored separately from its letter ends up on the wrong letter. All of that is inherent to reversing text rather than a fixable bug, which is why the word and line reversals, which never touch the characters, are the safe options when the text contains any of it.

Reversing the word order is a different job and has none of those problems, because the words themselves are never touched. Punctuation moves with the token it is attached to, so "hello, world" becomes "world hello," with the comma still on the second word. The gaps are kept but mirrored, so a double space after the first word comes back before the last, and nothing is collapsed. The one behaviour to know is that a multi-line block is treated as a single sequence of words, because a line break is whitespace: the last line ends up first. When the lines matter β€” a list, a set of steps, a log β€” reverse the line order instead, which keeps each line intact and only changes their sequence.

Right-to-left text is the case where the result can look wrong when it is not. Arabic and Hebrew are stored in logical order and laid out right to left by the browser, so reversing the characters or the words changes the underlying string correctly and the rendered result is not the mirror image people expect. That is bidirectional layout doing its job, not the reversal failing.

What people use it for

  • Putting the words of a sentence into the opposite order
  • Reading a line that someone wrote backwards as a puzzle
  • Flipping a log or a changelog so the newest entry sits at the top
  • Checking a phrase for a palindrome by setting the two boxes side by side
  • Spelling a name backwards for a username or a joke
  • Reversing the letters inside each word by running the character pass and then the word pass

Questions

Characters reverses letter by letter; word order reverses the words and leaves each one readable; line order reverses the lines and leaves each line intact.

Unicode, the Unicode standardMDN, working with strings
Was this tool any good?
Internal signal only Β· I use it to find the tools worth rebuilding