Text copied from PDFs, emails, Word documents, spreadsheets, and web pages rarely arrives clean. It brings invisible baggage: doubled spaces, hard line wraps in the middle of sentences, trailing tabs, non-breaking spaces, duplicate rows, stray HTML tags, and inconsistent capitalisation. Cleaning a 500-line list by hand wastes an hour and still leaves stragglers behind. This guide lays out a reliable step-by-step clean-up workflow, explains the invisible characters that break searches and imports, and shows which order prevents rework.

Why the order of clean-up steps matters

If you remove duplicates before trimming spaces, "Mumbai" and "Mumbai " look like two different entries and both survive. If you sort before normalising case, "apple" and "Apple" land in different places under case-sensitive sorting. Following one consistent pipeline eliminates almost every edge case:

  1. Strip markup and normalise whitespace (spaces, tabs, invisible characters, blank lines).
  2. Fix line breaks (rejoin hard-wrapped PDF paragraphs or split combined lines).
  3. Normalise casing (lower case, Title Case, or identifier style).
  4. Run targeted Find & Replace (standardise spellings, abbreviations, or delimiters).
  5. De-duplicate (now that identical items look identical).
  6. Sort (alphabetical or natural numeric order as the final step).

Step 1: Eliminate extra spaces and invisible characters

Start with Remove Extra Spaces. It collapses repeated spaces and tabs into single spaces, trims leading and trailing whitespace on every line, and removes or collapses blank lines. More importantly, it normalises invisible characters that look like spaces on screen but fail exact comparisons in Excel, SQL, and code:

CharacterCode pointWhere it comes fromWhat it breaks
Non-breaking spaceU+00A0Web pages, Word, Notion, macOS Option+SpaceSQL WHERE matches, CSV joins, regex
Zero-width spaceU+200BPDFs, Slack/Teams copy-paste, CMS editorsDuplicate checks, URLs, JSON keys, code identifiers
Byte-order mark (BOM)U+FEFFExcel UTF-8 CSV exports, NotepadFirst column header mismatch (id)
Carriage return\r\n vs \nWindows vs macOS/Linux filesDiff noise, shell script errors, line-end regexes
Horizontal tab\tCopied spreadsheet cells, code blocksVisual alignment, inconsistent delimiters

One important nuance for Indian and emoji text: zero-width joiners (U+200D) and zero-width non-joiners (U+200C) are meaningful inside Devanagari conjuncts, Persian/Arabic scripts, and compound emoji (like 👨‍👩‍👧‍👦). Good cleaners preserve ZWJ and ZWNJ while stripping stray zero-width spaces.

Step 2: Fix PDF hard line wraps

PDFs store positioned text fragments rather than flowing paragraphs, so copying a paragraph from a PDF inserts a newline at the end of every visual line. Before editing:

  • Preserve real paragraph breaks (double newlines \n\n) by temporarily replacing them with a marker like @@PARA@@ in Find and Replace (with RegEx mode on).
  • Replace remaining single newlines \n with a single space, and fix hyphenated line-end word breaks with regex -\s+ where appropriate.
  • Replace @@PARA@@ back with \n\n, then run Remove Extra Spaces to tidy any doubled spaces.

Step 3: Normalise capitalisation

“bengaluru”, “Bengaluru”, and “BENGALURU” mean the same city to a human but create three separate buckets in a pivot table or SQL GROUP BY. Open the Case Converter to standardise headings to Title Case, UI copy to Sentence case, email lists to lowercase, or column headers to snake_case. See camelCase, snake_case and URL Slugs for naming rules across languages.

Step 4: Systematic Find & Replace

Before removing duplicates, standardise known synonyms and formatting quirks with Find and Replace. Common clean-up patterns:

GoalFind (RegEx on)Replace with
Strip numbered prefixes (1. , 2) )^\s*\d+[.)]\s+(empty)
Strip bullet markers (- , • , * )^\s*[-•*]\s+(empty)
Swap “Last, First” to “First Last”^([^,]+),\s*(.+)$$2 $1
Remove inline HTML tags<[^>]+>(empty)
Convert straight smart quotes[“”] / [‘’]" / '
Extract only domain from URLs^https?://([^/]+).*$$1

For plain-text replacements, turn on Whole word when replacing short words (“cat” without changing “category”) and Match case when replacing acronyms (“US” without touching “us”). If you need to test a tricky pattern first and see every match highlighted in place, try the Regex Tester and read Regular Expressions for Beginners.

Step 5: Remove duplicate lines cleanly

Once spacing, case, and spelling variations are normalised, run Remove Duplicate Lines. It preserves the original order by keeping the first occurrence of each line and reports exactly how many duplicates were dropped. Keep Trim whitespace and Remove empty lines enabled for contact lists, keyword exports, SKU lists, and log messages. Toggle Case Sensitive off for emails and tags, or on for case-sensitive IDs and URL paths.

Step 6: Sort, reverse, or reshape the final list

Finish with Sort Lines. Choose the sort mode that matches your data:

  • Natural Number Sort whenever entries contain numbers (step 1, step 2, step 10 instead of step 1, step 10, step 2).
  • By First Number in Line for sorting scores, prices, or priorities embedded in text.
  • Length (Shortest / Longest First) for auditing meta titles, slogans, or domain names.
  • Random / Shuffle for prize draws, A/B test splits, or shuffling quiz questions (powered by crypto.getRandomValues).

Need the newest log entry at the top without sorting alphabetically? Use Reverse Text & Lines in Reverse Line Order mode. Need to wrap every cleaned line in quotes or generate numbered checklists? Text Repeater handles bulk repetition with custom separators and line numbers, while Lorem Ipsum generates realistic placeholder copy for layouts.

Worked example: cleaning a messy contact export

Suppose you pasted a messy list of emails and cities from three different emails:

  Asha@Example.com  
- rahul@example.com
asha@example.com

  Rahul@Example.com   
- priya@example.com
  1. Find & Replace regex ^\s*-\s* → empty removes the stray bullets.
  2. Remove Extra Spaces trims leading/trailing spaces and drops the blank line.
  3. Case Converter → lowercase unifies Asha@Example.com and asha@example.com.
  4. Remove Duplicate Lines drops the 2 duplicates, leaving 3 unique addresses.
  5. Sort Lines (A → Z) outputs a clean, alphabetical list ready for import.
asha@example.com
priya@example.com
rahul@example.com

If your data is tabular — rows and columns with mixed dates, broken quotes, or numbers stored as text — move to the CSV cleaning guide, and check final character limits in How to Count Words and Characters.