TextyConverterbeta
⌘K

Remove Extra Spaces

Collapse runs of multiple spaces into a single space. Tabs and newlines are preserved.

0 characters
0 characters

About Remove Extra Spaces

This tool collapses runs of two or more spaces into a single space. Tabs and line breaks are preserved exactly. Useful for cleaning up text where the spacing has gone irregular — common with OCR output, scraped web content, or hand-edited prose.

When to use it

  • Cleaning up text where someone hit space twice between words
  • Normalizing OCR output that uses variable spacing
  • Fixing prose after global find-and-replace introduced double spaces
  • Preparing text for consistent tokenization

How it works

The regex / {2,}/g matches two or more consecutive ASCII spaces and replaces each match with a single space. Tabs, newlines, and other whitespace characters are not touched.

Examples

Hello   world.  How  are  you?
Hello world. How are you?

Frequently asked questions

Are tabs affected?
No. Only ASCII space characters are collapsed. Use trim-leading or tabs-to-spaces if you also want to handle tabs.
Does it remove single leading/trailing spaces?
No. The regex requires two or more in a row. To trim ends, run trim-all first.
Does it collapse spaces inside quoted strings?
Yes — the tool is purely textual and doesn't understand quotes or other context. If quoted strings should preserve their spacing, do it manually.

Related tools