How can I reverse a line in Notepad++?

You can do an iterated search and replace to reverse the string, after you have marked the beginning of the string with a special character (I use the percent sign % in the example)

search: (%)(.*)(.)

replace: \3\1\2

enable "regular expressions" in search and replace.

repeat the operation until the string is reversed.


UPDATE: I have added a Python-3 "reverse the clipboard text" script.
This Python-3 script caters for Unicode text; ie. all text...

# original # Ĥĕłłō ŵōŗłđ in Unicode  
# reversed # edocinU ni đłŗōŵ ōłłĕĤ  

Because no integrated solution has been presented (yet), I'll mention a Unix-tools work-around.

Download the utilities mentioned in the source (below), and put them into a PATH'd folder.
Pop the code (below) into a .cmd file and call it anything you like. (it to, must of course be in a PATH'd folder).
Create a Windows shortcut to the .cmd (put it somewhere in your StartMenu, and set it to run minimized)... and assighen a Shortcut-Hotkey to it.

You can then just copy the text of your choice to the clipboard and press your Hotkey... Done! .. the reversed text replaces the selected text.

If you prefer you can set up a NotePad++ macro to select and copy an entire line.. (take note of the new-line char(s) at the end of the text.

Also, as mentioned in the source notes. This workd for single-bytes character sets..

sed.exe may be able to handle Unicode, but I haven't quite worked that one out yet... If you happen to know how to do this, please post the info, either here or perhaps in my posting of a specific qustion abut this issue: can-gnu-sed-for-windows-handle-unicode

This is the sed.exe version:

@echo off
  ::==============================================::
  :: FUNCTION: Reverse the text in the clipboard. ::
  ::    8-bit characters only (ANSI).             ::
  :: It removes all \r and \n characters, because ::
  :: because sed.exe adds a trailing line-feed    ::
  :: Four `NIX utilities are used.                ::
  ::    2 gclip.exe  (GNU)                        ::
  ::    1 pclip.exe  (GNU)                        ::
  ::    3 gsed.exe   (GNU)                        ::
  ::    4 tr.exe (is `NIX, but maybe not GNU)     ::
  ::==============================================:: 
  >   "%temp%\%n0.sed" echo /\n/!G
  >>  "%temp%\%n0.sed" echo s/\(.\)\(.*\n\)/^&\2\1/
  >>  "%temp%\%n0.sed" echo //D
  >>  "%temp%\%n0.sed" echo s/.//
  pclip.exe | sed.exe -f "%temp%\%n0.sed" | tr.exe -d "\r\n" | gclip.exe  
  del "%temp%\%n0.sed"
goto :eof  

Here is the Python-3 version:

##==============================================##
## FUNCTION: Reverse the text in the clipboard. ##
##           The text is handled as unicode.    ##
## Using Python-3.1.2                           ##
##  with Python-Win32-extensions for Python-3.1 ##
##==============================================##
import win32clipboard as w
w.OpenClipboard() 
## CF_UNICODETEXT == 13
s=w.GetClipboardData(13)
w.SetClipboardData(13,s[::-1]) 
w.CloseClipboard() 

If you don't need to do it that often you could copy the line into this online tool to do the reversal.


I realise this uses another tool, but you can reverse text in Excel and then copy it back. Create a spreadsheet and add this macro:

Sub ReverseText()
    Cells(Selection.Row, Selection.Column + 1) = StrReverse(Selection.Value)
End Sub

If you intend to use this feature regularly, assign the macro to a button on the toolbar for easy access. Copy some text into any cell. Ensure the cell is selected and run the macro. Copy the generated text back to Notepad++.

Surprising that this simple feature is not available in Notepad++ or through a plugin like TextFX.


The BinHex plugin version 2.0 of Notepad++ has a String reverse function implemented.

You can mark the string that should be reversed and hit Ctrl+R.