By kodewright · Published: 2026-05-08 · Updated: 2026-11-04
How to Remove Extra Spaces From Text Online (Fast Fix)
Paste-and-fix: remove double spaces, non-breaking spaces, and PDF line breaks in seconds. Free browser tool, no upload required.

Paste the text into Remove Spaces, tick "Remove extra spaces", and copy the result. Every run of regular spaces becomes a single space and the ends of the text get trimmed. The option leaves non-breaking spaces, tabs and zero-width characters alone, and that gap explains most complaints of the "I removed the spaces and some are still there" kind.
I built the tool so the cleaning happens in your browser tab. Nothing is uploaded, because there's no server on the other end to keep a copy.
What each option does
There are seven options. They stack, and the preview shows what would change before you copy anything. I checked the descriptions below against the tool's code, because a few of them differ from what the option names suggest.
| Option | What it does | Example (· is a space, ↵ a line break) |
|---|---|---|
| Remove extra spaces | Collapses every run of regular spaces into one and trims the start and end of the whole text | word··word → word·word |
| Fix PDF line breaks | Turns single line breaks inside a paragraph into spaces and keeps blank-line paragraph breaks | quick·brown↵fox → quick·brown·fox |
| Remove all line breaks | Replaces every line break with a space | line·1↵line·2 → line·1·line·2 |
| Remove empty lines | Deletes every blank line, so paragraphs end up on consecutive lines | para↵↵↵para → para↵para |
| Trim line endings | Strips spaces at the end of each line; leading spaces stay | hello··↵ → hello↵ |
| Remove special characters | Deletes every non-ASCII character | résumé → rsum |
| Straighten quotes | Curly quotes become straight ones | “hi” → "hi" |
Two things to know before you tick boxes. "Fix PDF line breaks" doesn't repair hyphenation: infor-↵mation becomes infor- mation. And "Remove special characters" removes accented letters along with everything else, so keep it away from German, French or Ukrainian text.
Why pasted text arrives with extra spaces
A PDF stores letters at coordinates, not as words. When you copy from one, the reader guesses where words start from the gaps between glyphs, and justified or widely kerned lines can push the guess toward two spaces. Copying from a rendered web page is the other common source: the HTML uses in places, and it reaches your clipboard as U+00A0. Word has a non-breaking space shortcut (Ctrl+Shift+Space) too, and I'd expect some templates to use it.
On screen none of these look different from a normal space. That's why they only show up later, in a word count, a search, or a regex that doesn't match.
Characters that look like spaces
| Character | Code point | Remove extra spaces | Matched by \s in JavaScript |
|---|---|---|---|
| Regular space | U+0020 | Collapsed to one | Yes |
| Non-breaking space | U+00A0 | Left alone | Yes |
| Thin space | U+2009 | Left alone | Yes |
| Em space | U+2003 | Left alone | Yes |
| Zero-width space | U+200B | Left alone | No |
The last column surprised me when I ran it. Plenty of write-ups claim \s skips the non-breaking space, but in current JavaScript it matches it. The one that slips through every \s pattern is the zero-width space.
What non-breaking and zero-width spaces break
I ran the string "New\u00A0York" through Intl.Segmenter in Node 22 and got two words, the same as with a regular space. The Word Counter on this site uses the same API, so a stray non-breaking space doesn't change its count. Code that splits on a literal space is different: "New\u00A0York".split(' ') returns one item.
Zero-width spaces are the nastier case. They have no width, so editors show nothing, but a regex like /\s+/ doesn't treat them as whitespace and a string comparison sees two different strings.
In my own work the messy whitespace mostly comes from logs, CSV files and user input in apps, not from Word documents. I've also been bitten once by a bug caused by a non-breaking space in code or data. The same kind of invisible character turns up when you paste from a PDF, which I touched on in how many words per page.
Fixing them with regex in Find & Replace
The Remove Spaces options don't convert non-breaking or zero-width spaces, so for those I switch to Find & Replace with the Regex toggle on. The tool only lets you set case sensitivity and global matching, so the patterns below need no flags. Run them in this order:
- Find
[\u00A0\u2000-\u200A], replace with a single space. This covers the non-breaking space and the whole U+2000–U+200A block (en space, em space, thin space and so on). - Find
\u200B, leave Replace empty. Zero-width spaces go. - Find
[ \t]+, replace with a single space. This collapses runs of spaces and tabs without touching line breaks. - Find
(?<=[^\n])\n(?=[^\n]), replace with a space. This joins mid-paragraph line breaks from a PDF and keeps the blank lines between paragraphs.
Don't use \s+ for step 3. It matches newlines too, so your paragraphs collapse into one block. For the full pattern syntax, the regex find and replace guide covers capture groups and quantifiers.
The order matters. If you collapse spaces first, a non-breaking space sitting next to a regular one survives, and step 1 then leaves you with a double space again.
When not to strip whitespace
Cleaning is fine on prose and destructive on anything where indentation means something. "Remove extra spaces" collapses leading spaces too, so a four-space indent becomes a single space.
In Python the indentation is the block structure, so you either get an IndentationError or, worse, statements that quietly move out of their loop. YAML nests keys by leading spaces, which means a cleanup can reparent a key and still leave a valid file that means something else. In Markdown, four leading spaces make a code block and two trailing spaces make a hard line break, so "Trim line endings" silently reflows paragraphs. In a TSV the tabs are the column separators, and in a patch file the leading space, + and - are the format.
For those files, make the one change you need with a precise regex and leave the rest alone.
A quick triage before you clean
- Search for two spaces in a row. Matches mean double-space contamination.
- Turn on Regex in Find & Replace and search
\u00A0. Matches mean non-breaking spaces. - Search
\u200Bfor zero-width spaces. - Look for lines that stop mid-sentence. That's the PDF line-break problem.
Then tick only the options you need. The preview pane shows the result before you copy it.
After the text is clean
Cleaning usually comes first in a longer job. Once trailing spaces are gone, apple· and apple compare as equal, so do it before you sort the lines alphabetically, where case sensitivity and locale collation can also change the order.
Invisible characters are also a common cause of false differences in a diff: two lines that look identical come back as changed because one ends in a non-breaking space or a CRLF. Clean both versions first, then compare the two text files online.
