Clean up a text before publishing it
Published · Updated 2 min read
A text copied from an email, a PDF or a spreadsheet often carries invisible flaws: double spaces, random capitals, repeated lines. Before publishing, three cleanups almost always do the job, in the right order.
Extra spaces
With the Find and replace tool in regular expression mode, the pattern " {2,}" preceded by a space replaces two or more spaces with a single one. A text such as "Hello world" becomes "Hello world". To remove the spaces left at the end of a line, the expression " +$" (a space, then a plus and a dollar sign) acts on each line. If you do not want to use a regular expression, you can also search for a double space as plain text and replace it with a single one, repeating the operation until none are left.
Case
Case means capital and lowercase letters. The "Title case" mode puts a capital at the start of each word: "hello MY world" becomes "Hello My World". Read the result carefully: small words such as "of" or "the" often should not have a capital in a title, and in languages with elisions, such as French, the letter after an apostrophe also receives a capital, which is not correct.
Duplicates
To remove duplicate lines, sort the lines while removing duplicates. Careful: the comparison tells capitals apart, so "banana" and "Banana" remain two different lines, like "apple" and "Apple". Put the text in a uniform case first if you want to merge them. Empty lines are removed by this sort.
In which order
Start with the spaces, which distort comparisons, then set the case, and finish with the sorting and the duplicates. In the reverse order, two lines identical except for a space would not be recognized as duplicates.
When to clean a text
After copying from a PDF, an email or a spreadsheet, before importing a list into a tool, or before publishing an article: double spaces, inconsistent capitals and repeated lines are fixed in a few steps.
Check before pasting
Read the whole final text before pasting it elsewhere. Automatic cleanups save time, but only a reread catches a proper name turned to lowercase or a line removed by mistake.
Frequently asked questions
- How do you remove double spaces?
- With Find and replace in regular expression mode, the pattern " {2,}" preceded by a space replaces two or more spaces with a single one.
- How do you remove duplicate lines?
- Sort the lines while removing duplicates. The comparison tells capitals apart: "banana" and "Banana" remain two lines.
- Why does "D'été" get a capital after the apostrophe?
- The "Title case" mode puts a capital after the apostrophe, which is not correct in French. Read the result again.
- In which order should you do the cleanups?
- Spaces first, case next, then sorting and duplicates.
