Skip to content
M2TOOLKIT

Text guide

How to Clean Up and Format Messy Text (From PDFs, Emails and Websites)

Fix broken line breaks, double spaces, curly quotes, invisible characters and duplicate lines in text copied from PDFs, emails and web pages — in the right order.

By M2Toolkit Editorial TeamPublished 6 min read

Quick answer

Work in this order: 1) join broken lines, 2) remove extra spaces and invisible characters, 3) straighten curly quotes if the text is going into code or a spreadsheet, 4) remove duplicate or empty lines, and 5) fix capitalization. The Text Cleaner handles steps 2 and 3 in one pass.

Text copied from PDFs, emails, websites and Word documents rarely pastes cleanly. Lines break in the middle of sentences, spaces double up, and invisible characters sneak in that break searches, formulas and code. Each problem has a quick fix — the trick is doing them in the right order.

What goes wrong, and where it comes from

ProblemUsually comes fromFix with
A line break every few wordsPDFs, emailsRemove Line Breaks
Double spaces, tabsWord, PDFs, aligned textText Cleaner
Invisible charactersWebsites, chat appsText Cleaner
Curly quotes “ ” breaking codeWord, macOS, phonesText Cleaner
Repeated lines in a listExports, merged listsRemove Duplicate Lines
ALL CAPS or random capsOld systems, typingCase Converter

The order that works

  1. 1
    Join broken lines first. Keep paragraph breaks (blank lines) and rejoin words hyphenated across lines. If you clean spaces first, you can lose the paragraph structure you need.
  2. 2
    Remove extra spaces, tabs and invisible characters. Zero-width spaces and non-breaking spaces look like nothing but make “find” fail and break code.
  3. 3
    Straighten quotes when the text is going into code, CSV files or a terminal. Leave curly quotes in prose — they're typographically correct.
  4. 4
    Remove duplicate and empty lines in lists.
  5. 5
    Fix capitalization last, once the text is otherwise final.
Try the free Remove Line BreaksJoin broken PDF lines into paragraphs, with hyphenated words repaired.

The invisible characters worth knowing

  • Non-breaking space (U+00A0): looks like a space, but formulas and searches treat it as different. Very common in text copied from websites.
  • Zero-width space (U+200B): takes no space at all. It can make two identical-looking words fail to match.
  • Soft hyphen (U+00AD): an invisible hint for where a word may break; it sometimes shows up as a stray hyphen.
  • Byte-order mark (U+FEFF): appears at the start of some files and can break the first column of a CSV.
Try the free Text CleanerRemoves invisible characters, extra spaces, tabs and more — each option switchable.

For anything else: find and replace with patterns

Regular expressions handle cleanups no preset covers. A few useful ones for the Find and Replace tool:

FindReplace withDoes
\s+$(nothing)Removes trailing spaces on each line (with multiline)
^\d+\.\s*(nothing)Strips “1. ” numbering from a list
(\w+)@(\w+)$1 at $2Rewrites emails to deter scrapers
\[\d+\](nothing)Removes citation markers like [12]

Frequently asked questions

Why does pasting from a PDF break every line?

PDFs store text as positioned lines, not paragraphs. When you copy, each visual line becomes a separate line. Joining lines while keeping blank-line paragraph breaks restores the original paragraphs.

Is it safe to paste private text into these tools?

Yes. M2Toolkit's text tools process everything in your browser, so the text never leaves your device.

About this guide

The people who build M2Toolkit's tools write these guides. Every formula and example in an article is checked against the matching tool, and articles are reviewed when the tool changes.

Tools mentioned in this guide