Trim Whitespace

Strip leading and trailing whitespace from every line. Internal runs of spaces collapse to a single space. Cleans up text exported from PDFs, spreadsheets, and forms.

Example: hello world foo bar hello world foo bar

Strips leading and trailing whitespace (spaces, tabs) from every line, and collapses runs of internal whitespace into single spaces. The most common normalisation step before further processing.

Especially useful for text copied from PDFs (which often arrives with stray double-spaces), spreadsheet exports, or form-pasted user input.

Use cases

Cleaning pasted form data

User-entered emails and names often arrive with leading/trailing spaces from copy-paste. Trim before storing or comparing.

Normalising PDF text

PDF copy-paste produces erratic spacing. Trim and collapse to get a clean string.

Pre-deduplication step

Before removing duplicates, trim — otherwise "hello" and "hello " stay distinct.

Spreadsheet column cleanup

Copy a column out of Excel, trim, paste back — fixes alignment issues from inconsistent spacing.

Search-string preparation

Trimming queries before sending them to a search API avoids "no results" caused by trailing whitespace.

Frequently asked questions

Does it remove tabs as well as spaces?

Yes. Tabs, spaces, and any other Unicode whitespace are all stripped.

Will it collapse internal whitespace too?

Yes — runs of two or more whitespace characters between words collapse to a single space. If you need to preserve double-spaces, do the leading/trailing trim manually.

Does it remove blank lines?

No — empty lines stay as empty lines. Use Remove Blank Lines for that.

Will it affect non-breaking spaces?

Yes — JavaScript's \s regex matches non-breaking spaces, so they're collapsed too. If you need to preserve  , use a custom regex.

Embed our tools on your website

Free for any site. No signup. Iframe loads from our servers and stays up-to-date automatically.

📋 Embed the Word Counter

Copy this snippet:

Live preview:

📋 Embed this Trim Whitespace

Copy this snippet:

Live preview:

Want more options? All embeddable tools →