Trim Trailing Whitespace Online

Remove invisible trailing spaces and tabs from the end of every line without affecting paragraph indentation.

Trim Trailing Whitespace strips spaces (U+0020) and horizontal tabs (U+0009) from the end of every line using the multiline regex s/[ \t]+$//gm while preserving leading indentation. For example, Line 1 \n Line 2\t\t (21 chars) becomes Line 1\n Line 2 (15 chars, 6 trailing chars removed).

Fixed:
0 Characters
0 Words
0 Sentences
🧹 Remove
🔤 Convert
📑 Format
Copied to clipboard

Why Should You Trim Trailing Whitespace from Code and Text?

Removing trailing spaces and tabs at line ends eliminates noisy Git diff warnings, fixes CSV/SQL string-matching failures where "value " !== "value", and prevents unintended Markdown hard line breaks.

Trailing whitespace consists of invisible spaces and tabs left at the very end of lines of text or code. While invisible to the human eye, trailing spaces cause major issues downstream:

  • Git Diffs & Code Reviews: Trailing spaces trigger noisy, dirty diffs across entire files during version control commits.
  • CSV & Database Matching: String lookups fail because "Smith " does not match "Smith".
  • Markdown Formatting: In Markdown, two trailing spaces force a line break, which can cause accidental line splitting.

How Does the Trailing Whitespace Trimmer Algorithm Work?

The engine splits text on \n, applies line.replace(/[ \t]+$/, "") to each line, and rejoins with \n—leaving leading indentation (^[ \t]+) completely untouched.

Text Cleaner scans each line of text and strips any sequence of spaces, tabs, or non-breaking spaces before the newline character, while strictly preserving intentional indentation at the beginning of each line.

  • Worked Before / After Example: Input Line 1 with invisible trailing spaces. \nLine 2 with trailing tabs.\t\t\nLine 3 with clean ending. (97 characters, 3 lines; 4 trailing spaces on Line 1, 2 trailing tabs on Line 2) → Output Line 1 with invisible trailing spaces.\nLine 2 with trailing tabs.\nLine 3 with clean ending. (91 characters, 3 lines; 6 trailing whitespace characters removed).
Line Pattern & Regex Rule Input Example (Before) Output Result (After) Trailing Chars Removed (count)
Trailing Spaces ([ ]+$, U+0020) "Smith" (11 chars) "Smith" (7 chars) -4 trailing spaces removed
Trailing Tabs (\t+$, U+0009) return true;\t\t (14 chars) return true; (12 chars) -2 trailing tabs removed
Indented Code Line (Leading Preserved) const x = 1; (19 chars) const x = 1; (16 chars) -3 trailing spaces; 4 leading kept
Markdown Accidental Hard Break ( $) Paragraph line \nNext line (26 chars) Paragraph line\nNext line (24 chars) -2 trailing spaces removed

When Should You Use All-in-One Paste Repair Instead?

Use Clean Pasted Text when your clipboard also contains zero-width spaces (U+200B), smart quotes, or em dashes in addition to trailing spaces.

If your pasted text also carries smart quotes, em dashes, or zero-width characters, try our comprehensive Clean Pasted Text tool to fix all formatting problems in one click.

How to use this tool:

  1. Paste or type your text into the editor box above.
  2. Click the highlighted action button to run the transformation instantly on your device.
  3. Click Copy to place the cleaned text onto your clipboard.

More Free Online Text Tools

Cleaning & Stripping
Clean Pasted Text Remove Em Dash Remove Line Breaks Remove Invisible Chars Straighten Quotes Strip HTML Strip Markdown
Case Converters
All 11 Case Converters Sentence Case camelCase Converter snake_case Converter
Formatting & Analytics
Remove Duplicate Lines Alphabetize List Word & Character Counter

Clean text from any app with the Share Sheet.

Select text in Safari, Mail, or Notes and share it to Clean Text. The cleaned version is copied back to your clipboard with a summary of what was fixed.

  • Works inside Safari, Mail, Notes, Word, and Slack
  • Counts and audits damage: '2 em dashes, 3 invisible characters removed'
  • 100% on-device: zero network requests, zero telemetry, full privacy
  • Available on iPhone, iPad, and Mac
Text Cleaner: Case Converter App Screenshot