Advertisement

How to replace multiple spaces with one in Notepad++

Zeynel -
31 days ago

Notepad++ lets you find and replace quite a few things in your text, like deleting empty lines or duplicate lines. But not all things are readily available in the Edit menu. 

How to get rid of multiple spaces?

If the number of spaces isn't constant, you'll need this trick to replace them instantly with a single space. After reminding you to have a backup of your file, here is how you can do it.

- Open the Find box (Ctrl + F)

- Click the Replace tab

- In the Find what: box, type + and a space. Alternatively, if you want to match the newline/tab characters along with spaces, type \s{2,} in the Find what box.

- For Search Mode, select Regular Expression

- It will now match the multiple spaces. You can type whatever you want to replace with in Replace with: box. Typically this will be a single space.

Now depending on what you want to do, you can use the Find Next, Replace, or Replace All buttons to get the desired result.

Without the help of regex, you'd need to use Replace multiple times by replacing a fixed number of spaces; e.g. replacing 3 spaces with one. With this solution, it's possible to replace them "properly" in single pass.

Did you find this article useful?
0 0
Share this page on:



Only registered users can post links.
Checking site status...
 
No comments yet. Ask, or type the first one!