How to Remove Extra Spaces From Text (4 Methods, With Examples)
You paste a paragraph from a PDF, and suddenly there are double spaces between half the words, random line breaks in the middle of sentences, and a trailing blank line at the end. Here's why that happens and four ways to fix it.
Why extra spaces show up in pasted text
Extra whitespace isn't random — it usually comes from how the source document was formatted before you copied it:
- PDFs often encode text in columns or fixed-width blocks. When you select and copy, the PDF reader inserts a line break wherever a visual line ended, even mid-sentence, and can add stray spaces where text was justified.
- Old typing conventions. Many people were taught to type two spaces after a period, a holdover from monospaced typewriter fonts. That habit shows up as visible double spaces once pasted into a proportional font.
- Word processors sometimes insert non-breaking spaces (a different character to a regular space, invisible to the eye) that don't behave the same way when pasted elsewhere.
- Chat and email exports frequently carry extra blank lines from signature blocks, quoted reply markers, or message spacing.
Method 1: Find and replace in Word or Google Docs
Both Microsoft Word and Google Docs support find-and-replace. To collapse double spaces into single spaces:
- Open Find & Replace (Ctrl+H on Windows, Cmd+Shift+H in Google Docs).
- Search for two spaces (press the spacebar twice) and replace with one space.
- Click "Replace All" repeatedly until it reports zero replacements — this catches runs of three or more spaces, which collapse gradually with each pass.
This works well for simple double-space cleanup but won't fix stray mid-sentence line breaks or non-breaking spaces without enabling regular expressions, which Google Docs doesn't support natively.
Method 2: Regex in a code editor
If you're comfortable with regular expressions, editors like VS Code or Sublime Text let you search with regex enabled. A few useful patterns:
{2,}→ replace with a single space, to collapse any run of two or more spaces.^\s+|\s+$(with multiline mode) → replace with nothing, to trim leading/trailing whitespace from every line.\n{3,}→ replace with two newlines, to collapse three or more blank lines down to one.
This is the most flexible method, but it requires comfort with regex syntax and isn't practical if you just need a quick fix.
Method 3: A dedicated whitespace tool
For a one-click fix with no formulas to remember, paste the text into a tool built specifically for this, like our own Whitespace Trimmer. You can toggle exactly which rules to apply — collapsing multiple spaces, trimming line edges, removing blank lines, and converting tabs — without touching a find-and-replace dialog or writing regex. Because it runs in your browser, the text you paste is never uploaded anywhere.
Method 4: Browser extensions and OS-level tools
Some browser extensions and system-level text expanders include whitespace-cleaning shortcuts, letting you clean text before you even paste it. These can be convenient if you're doing this constantly across many apps, though they add another piece of software to install and trust with your clipboard contents.
Which method should you use?
For a one-off cleanup, a dedicated tool is the fastest route — no formulas, no software installs, and it handles tabs and blank lines alongside plain double spaces in one pass. If you're already comfortable with regex and working inside a code editor, that gives you the most control. Find-and-replace in Word or Docs is fine for simple double-space cleanup but starts to feel tedious for anything more complex.