Home / Guides / How to remove extra line breaks and double spaces from text
How to remove extra line breaks and double spaces from text
Extra gaps usually come from repeated spaces, trailing spaces, runs of blank lines or lines that were hard-wrapped at a fixed width. Collapse them with a cleaner or a find-and-replace, but leave line breaks alone in poems, addresses, tables and code, where they carry meaning.
Pasted text often arrives with spacing nobody chose: two spaces after every full stop, three blank lines between paragraphs, or each line of a paragraph ending in its own line break. They are easy to ignore on screen and annoying the moment you edit, count or reformat the text.
The kinds of extra spacing
- Double spaces, often after full stops. This is a typewriter-era habit that most current style guides no longer follow. Web pages hide it because HTML collapses repeated spaces when it displays text, but the extra space is still in the source.
- Trailing spaces at the end of a line, which you can't see but which make lines differ when you compare or sort them.
- Runs of blank lines, where one empty line would do.
- Hard-wrapped lines, where every line ends in a line break at a fixed width. This is common in text copied from PDFs and from older plain-text emails.
- Mixed line endings. Windows files end lines with two characters (carriage return and line feed), macOS and Linux use one (line feed), and very old Mac files used a carriage return alone. A tool expecting one style can show the others as an extra blank line or a stray symbol.
Paragraph breaks versus line breaks
In a word processor, pressing Enter starts a new paragraph and pressing Shift+Enter inserts a line break inside the same paragraph. When you copy text out of a document, both can turn into a newline in the plain text, so you can't always tell them apart afterwards.
The practical rule is to keep one blank line between paragraphs and nothing more. If your text uses single newlines everywhere and you want proper paragraphs, you need to decide which newlines are real paragraph breaks before you clear the rest.
The quick way: use a cleaner
- Open Paste & Wash and paste your text.
- Leave Odd and repeated spaces on to collapse doubled spaces and trim trailing ones.
- Leave Line breaks on to fix line endings and collapse runs of blank lines.
- If the text was hard-wrapped, as in a PDF copy, switch on Join broken lines. It rejoins the lines of each paragraph and keeps list items separate.
- Check the report to see how many of each were found, then copy the result.
Doing it by hand
In Word, open Find and Replace with Ctrl+H. Search for ^p^p and replace with ^p to turn doubled paragraph marks into single ones, and repeat until nothing is found. For doubled spaces, tick Use wildcards, search for a space followed by {2,} and replace with a single space.
In Google Docs, open Find and replace, tick Match using regular expressions, search for a space followed by {2,} and replace with one space. Google Docs is less flexible with line breaks in find and replace, so for long runs of blank lines a cleaner or Word is easier. A code editor such as Visual Studio Code can match line breaks directly when its regular expression option is switched on.
One warning: if you replace two spaces with one only once, a line with four spaces becomes two. The {2,} pattern avoids that by matching any run of two or more in a single pass.
When to leave line breaks alone
- Poems and lyrics, where each line break is part of the work.
- Addresses, which depend on one item per line.
- Code, configuration files and logs, where line breaks and indentation are part of the syntax.
- Tables pasted as text, where the layout depends on both line breaks and spacing.
Check your result
After cleaning, compare the character and word counts shown before and after. A drop in the character count, with the word count staying about the same, is what you expect, because spaces and line breaks have gone but no words have. The word count can fall slightly if a standalone item such as a reference marker or an emoji was removed. If it falls by much more than that, scroll through the result before you use it.
A worked example
Suppose you paste an email draft that has two spaces after every full stop, three blank lines between paragraphs and invisible spaces at the end of some lines. After cleaning, every full stop is followed by one space, there is a single blank line between paragraphs and the trailing spaces are gone. The words are identical. Only the spacing changed, and the report records how many of each kind were fixed.
For an excerpt from a PDF where every line ends in a line break, Join broken lines produces one flowing paragraph per block. It joins the lines but does not rejoin a word that was split with a hyphen at the end of a line, so after using it, search the text for a hyphen followed by a space and repair those by hand.
Does trimming spaces change your word count? Not by itself. Words are separated by spaces and line breaks, so removing the extra ones changes the character count and the number of lines, but not the number of words. The count falls only if a standalone item, such as a reference marker or an emoji, is removed as well.
Try the cleaner to see what is hiding in your own text.