Copied text arrives carrying junk. A sentence lifted from a PDF or a web page often brings extra spaces, stray tabs, and a character that looks like a space but is not. Strip them out, and the text turns clean. Leave them in, and it reads as sloppy. Here is how to remove double spaces, trim whitespace from the start and end of lines, collapse multiple spaces into one, and kill the hidden non-breaking space that hitches a ride in copied content.

Why Extra Spaces and Tabs Appear

Copy from a web page, an email, or a PDF, and you pull in formatting you never asked for. Paragraph indents, table alignment, line wrapping. All of it dumps extra characters into your text. Tabs (Unicode U+0009) look like spaces but are not. They align columns. They also wreck plain text. A non-breaking space (Unicode U+00A0, CHAR(160)) is worse. It is common in HTML and PDFs. It looks identical to a standard space, but it is a different character entirely. A basic space-removal tool will not touch it.

Using a Text Editor or Word Processor

The quickest route is Find and Replace. Open the dialog in your editor, put two spaces in the Find field, put one space in the Replace field. Run it. Run it again until no double spaces remain. This catches spaces. It ignores tabs and non-breaking spaces.

Stripping Multiple Spaces in Microsoft Word

Word can do it in one pass. Open Find and Replace, turn on 'Use wildcards'. In the Find field, enter the pattern {2,} (a space, then a curly brace containing '2,' and a closing brace). In the Replace field, put a single space. The wildcard matches two or more consecutive spaces and collapses them into one. Much faster than repeating a manual swap.

Clearing Tabs

Tabs need their own pass. Copy a tab character straight from the document and paste it into the Find field. Replace it with a single space, or with nothing if you want it gone. If your editor handles regular expressions, use \t. A space-only sweep will never catch them.

Using Spreadsheet Programs

Excel and Google Sheets ship with a function called TRIM. It strips leading and trailing spaces and collapses repeated spaces between words to a single space. Handy when data comes from an outside source.

Excel and Google Sheets TRIM Function

Use =TRIM(A1) where A1 holds the text. Leading and trailing spaces vanish. Multiple spaces between words collapse to one. But Excel's TRIM will not remove the non-breaking space (Unicode U+00A0, CHAR(160)). Combine TRIM with SUBSTITUTE to get it done: =TRIM(SUBSTITUTE(A1,CHAR(160)," ")). That swaps each non-breaking space for a standard one, then TRIM tidies the result.

Hunting Down Non-Breaking Spaces

You cannot see them. They still break your data. HTML uses them to keep words together, and copied web text is full of them. If TRIM leaves spaces behind, suspect non-breaking spaces. In Excel, SUBSTITUTE with CHAR(160) does the job. In Google Sheets, use the same CHAR(160) approach. The CLEAN function removes non-printable characters, but it does not touch non-breaking spaces.

Using Regular Expressions

Regex gives you a scalpel. The pattern \s+ matches one or more whitespace characters: spaces, tabs, line breaks. Swap \s+ for a single space, and every run of whitespace collapses into one. Line breaks go too. Use it only when you want that.

To collapse repeated spaces while leaving tabs and line breaks alone, use {2,} (a space followed by a quantifier meaning two or more). Replace with a single space. Tabs and newlines survive untouched.

Leading and trailing whitespace need their own pattern: ^\s+|\s+$. The caret ^ anchors to the start of a line. The dollar sign $ anchors to the end. The pipe | means 'or'. This matches whitespace at either edge. Replace with an empty string, and the text trims flush.

Step-by-Step Removing Extra Spaces in Any Text

A repeatable method for any editor that supports regular expressions (Notepad++, Sublime Text, even browser-based tools):

  1. Paste the text into a new document.
  2. Open Find and Replace (Ctrl+H on Windows, Cmd+H on Mac).
  3. Enable regular expressions. Look for a checkbox or a button labelled 'Regex'.
  4. In the Find field, enter {2,} (a space, then a curly brace with '2,' and a closing brace).
  5. In the Replace field, put a single space.
  6. Click 'Replace All'. Every run of two or more spaces collapses to one.
  7. To strip leading and trailing spaces: enter ^\s+|\s+$ in Find, leave Replace empty, click 'Replace All'.
  8. To clear tabs: copy a tab character by pressing Tab in the Find field. Replace with a space, or use \t if your editor supports it.
  9. To purge non-breaking spaces: copy one from a web page or use its character code. Swap it for a standard space, then rerun the space-collapse steps.

Handling Non-Breaking Spaces

Non-breaking spaces (Unicode U+00A0) cause disproportionate frustration. HTML relies on them to keep words together. Copied web text and PDFs are lousy with them. They look exactly like standard spaces. They are not. A find-and-replace for a space will skip right over them.

Kill them by swapping the non-breaking space character for a standard space first. In most editors, copy a non-breaking space from a document or use the character code. Excel accepts CHAR(160). In a regex-capable editor, \u00A0 or \x{00A0} works, depending on the flavour. Once they become standard spaces, run the TRIM function or the regex patterns above to clean up the mess.