Editly

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.

Table: Remove extra spaces collapses only the regular space U+0020 and leaves U+00A0, U+200B and U+2003 alone

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.

OptionWhat it doesExample (· is a space, ↵ a line break)
Remove extra spacesCollapses every run of regular spaces into one and trims the start and end of the whole textword··word → word·word
Fix PDF line breaksTurns single line breaks inside a paragraph into spaces and keeps blank-line paragraph breaksquick·brown↵fox → quick·brown·fox
Remove all line breaksReplaces every line break with a spaceline·1↵line·2 → line·1·line·2
Remove empty linesDeletes every blank line, so paragraphs end up on consecutive linespara↵↵↵para → para↵para
Trim line endingsStrips spaces at the end of each line; leading spaces stayhello··↵ → hello↵
Remove special charactersDeletes every non-ASCII characterrésumé → rsum
Straighten quotesCurly 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

CharacterCode pointRemove extra spacesMatched by \s in JavaScript
Regular spaceU+0020Collapsed to oneYes
Non-breaking spaceU+00A0Left aloneYes
Thin spaceU+2009Left aloneYes
Em spaceU+2003Left aloneYes
Zero-width spaceU+200BLeft aloneNo

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:

  1. 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).
  2. Find \u200B, leave Replace empty. Zero-width spaces go.
  3. Find [ \t]+, replace with a single space. This collapses runs of spaces and tabs without touching line breaks.
  4. 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

  1. Search for two spaces in a row. Matches mean double-space contamination.
  2. Turn on Regex in Find & Replace and search \u00A0. Matches mean non-breaking spaces.
  3. Search \u200B for zero-width spaces.
  4. 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.

Frequently Asked Questions

Why does pasted text have extra spaces?

A few usual sources. A PDF stores letters at coordinates rather than as words, so the text extractor guesses word boundaries from the gaps and sometimes inserts two spaces where there should be one. Web pages use &nbsp; entities, which reach your clipboard as non-breaking spaces (U+00A0). Some word processors can insert non-breaking spaces too. None of them look different from a normal space on screen, but they show up later as a wrong word count, a failed search or a regex that doesn't match.

What is a non-breaking space and why is it invisible?

A non-breaking space (U+00A0) is a space that stops a line from breaking at that spot, so 'New York' stays on one line. It's drawn exactly like a regular space (U+0020), so you can't tell them apart by looking. The Remove extra spaces option doesn't touch it. To turn it into a regular space, use Find & Replace with Regex on, search for \u00A0 and replace it with a single space. 'Remove special characters' also deletes it, but it deletes it outright, so the two words on either side fuse together.

What regex pattern removes multiple spaces in a row?

Use /[ \t]+/g and replace with a single space. It matches runs of spaces and tabs and leaves line breaks alone. To catch non-breaking spaces in the same pass, use /[ \t\u00A0]+/g. The u flag isn't needed for \u00A0, only for \p{...} property escapes. Avoid /\s+/g for this job: \s matches newlines as well, so your paragraphs would collapse into one block.

Why does the Remove Spaces tool have a separate 'Fix PDF line breaks' option?

Extra spaces and broken lines are two different problems. Copying from a PDF often leaves a hard line break at the end of every visual line, so one sentence ends up spread over several lines. 'Fix PDF line breaks' replaces each single line break with a space and keeps the blank lines between paragraphs. It doesn't repair words split with a hyphen at the end of a line: 'infor-' and 'mation' stay as two pieces. For that, use Find & Replace to remove the hyphen and line break, and run it before the PDF option.

Does removing extra spaces change my word count?

Collapsing regular double spaces doesn't, because words are counted by letter sequences, not by gaps. A non-breaking space doesn't change the count either in a tokenizer like Intl.Segmenter, which counts 'New York' as two words with either kind of space. Tools that split on a literal space may count it as one. The option that can lower your count is 'Remove special characters': it deletes non-breaking and other non-ASCII spaces, so 'New York' becomes 'NewYork', one word.

Can I remove spaces from a very large document without the page freezing?

The cleaning is a handful of regular expressions run in your browser, so a pasted blog post, email or report is no problem. I haven't timed it on files of many megabytes. For something that size, such as a big log, a command-line tool like sed is the safer choice.

What is the difference between 'Trim line endings' and 'Remove extra spaces'?

'Trim line endings' strips spaces at the end of every line and leaves leading spaces alone. 'Remove extra spaces' collapses every run of spaces into one, including indentation, and trims only the start and end of the whole text. Take the line ' hello world ': trimming gives ' hello world', removing extra spaces gives 'hello world'. If you tick both, trailing spaces are removed first, then the rest collapses.

Try Our Free Word Counter

Instantly count words, check readability, and analyze your text.

Open Word Counter