A pasted notice can have double spaces between words while its line breaks are already correct. You want to tidy the gaps without joining the lines or removing the blank line between paragraphs. A narrow find-and-replace pattern can make that change in one pass.
This procedure targets repeated ordinary spaces in plain text. Keep a copy of the original first, especially when spacing could represent indentation or columns.
Use a pattern that matches spaces only
Enter [ ]{2,} as the search pattern. There is one ordinary space between the square brackets. The brackets select that character, and {2,} means a run of two or more. Replace each run with one ordinary space.
This follows the character-class and repetition rules in MDN’s character classes guide and quantifiers guide. An existing single space is left alone.
A space here means U+0020, the usual space typed with the spacebar. The pattern does not include tabs, nonbreaking spaces or line-break characters. That limited scope is what keeps separate lines separate.
Clean a short notice with Find and Replace
Use this fictional workshop notice as a small test before processing a longer document. It contains three runs of repeated spaces:
Course: Clay bowls
Seats: 6
Bring an apron.
- Open Find and Replace Text and paste the notice into Your text.
- In Find, enter
[ ]{2,}exactly. Do not add slash delimiters around it. - Click Replace with and press the spacebar once. The field should contain one space, even though it looks almost empty. Leaving it empty would delete the matching gaps and join words.
- Enable Use regular expression and Replace all. Leave Whole word only off. Match case does not affect a pattern containing only spaces.
- Click Replace. Read the result below the controls and check Replacements made before using Copy.
The expected result is:
Course: Clay bowls
Seats: 6
Bring an apron.
The replacement count should be 3. It counts matching runs, not individual spaces removed: the three-space gap after the second colon is one replacement. The input box remains your original text; the edited version appears separately below it.
Why not search for all whitespace?
The broader expression \s+ also matches tabs and line breaks. Replacing its matches with a space can flatten a multiline notice into one line and remove paragraph separation. MDN’s character classes guide lists these additional whitespace characters.
For this task, leave [ ]{2,} unchanged. It will not fix a gap made from a tab or a nonbreaking space, even when that gap looks similar. A zero replacement count may mean the visible gap uses another character; it does not prove the document has no spacing problems.
Check meaningful spacing before copying
Indentation and aligned columns need a different decision
The pattern matches repeated spaces anywhere, including the beginning of a line. It can shrink deliberate indentation, disrupt columns aligned with spaces or change spacing inside code. Use it on prose whose repeated spaces are accidental. Select only the relevant prose section when a document also contains tables, code or preformatted material.
Review the output in its destination
Compare the original and result line by line. Confirm that every intended line and blank line remains, and that words still have a separating space. The guide to comparing two text drafts provides a useful review procedure for a longer edit.
Copy the result into its intended editor and check it again, since that editor may format pasted text differently. If your actual goal is to join wrapped lines instead, follow the separate line-break removal guide.
Apply the same rule in JavaScript
For a script processing plain text, the equivalent replacement is:
const cleaned = original.replace(/[ ]{2,}/g, " ");
The global flag applies the replacement to every matching run. The expression returns a new string rather than changing the original string value, as documented in MDN’s String.replace reference. Review cleaned before saving it over a file.