Advertisement

Remove Extra Spaces

Clean up your text by removing double spaces, tabs, and trailing whitespace.

Advertisement

Whitespace Cleaning Operations

Text copied from documents, web pages, or PDFs often contains invisible whitespace problems — extra spaces between words, tabs, non-breaking spaces, or inconsistent line breaks — that cause issues in code and data processing.

Common Whitespace Problems

Whitespace in Different Contexts

How do I remove extra spaces in a spreadsheet?

Excel and Google Sheets have a TRIM() function that removes leading, trailing, and consecutive internal spaces: =TRIM(A1). For non-breaking spaces, combine with SUBSTITUTE: =TRIM(SUBSTITUTE(A1, CHAR(160), " ")). This handles most copy-paste whitespace issues.

What regex removes extra spaces?

To collapse multiple spaces: replace + (two or more spaces) with a single space. To trim: replace ^\s+|\s+$ with empty string. Combined one-liner in JS: str.trim().replace(/\s+/g, ' '). The \s class matches spaces, tabs, and line breaks.

Why do pasted texts sometimes have invisible characters?

Word processors, PDFs, and web pages use special Unicode whitespace characters beyond regular space (U+0020): non-breaking space (U+00A0), en space (U+2002), em space (U+2003), zero-width space (U+200B), and others. Standard regex \s may not match all of them — use Unicode-aware regex or normalize to ASCII space first.