Small SEO Tools

How to Replace Nonbreaking Spaces in Copied Text

A copied paragraph can contain gaps that look like ordinary spaces but behave differently when the text wraps or a search runs. One possible cause is a nonbreaking space. Replace it only when the source intended an ordinary word separator.

This procedure targets the actual U+00A0 character in pasted plain text. It keeps existing line breaks and leaves other kinds of spacing alone.

Identify the character before changing the paragraph

An ordinary space typed with the spacebar is U+0020. A nonbreaking space is U+00A0. The latter is intended to keep adjoining text together during line breaking; the Unicode line breaking specification describes this nonbreaking behavior. It can be useful in a label, a name or a number-and-unit combination.

A run of accidental nonbreaking spaces between ordinary words can therefore be a problem in copied prose. However, a layout problem alone does not prove those characters are present. Keep the original and test a small affected section before replacing anything.

Do not identify the character only by the width of its gap. Ordinary spaces, U+00A0 and the distinct U+202F narrow no-break space can be hard to tell apart in a font. The search below targets one code point explicitly.

Try a sample with three nonbreaking spaces

The displayed sample contains U+00A0 after Bring, Meet and North. Its other gaps are ordinary spaces. Copy the whole sample, preserving the blank line and adding no final newline:

Bring a notebook.

Meet at North Hall.
  1. Open Find and Replace Text and paste the sample into Your text.
  2. Enable Use regular expression and Replace all. Leave Whole word only off. Match case does not affect this character pattern.
  3. In Find, enter the following six characters, beginning with one backslash. Do not add surrounding slashes:
\u00A0
  1. Click Replace with and press the spacebar once. The field must contain one ordinary space; an empty field would delete the gaps.
  2. Select Replace and inspect the separate result area.

The expected output is:

Bring a notebook.

Meet at North Hall.

Expect 3 Replacements made, 38 Characters before and 38 Characters after. The character total stays the same because each selected character becomes one different character. Both stored line breaks remain, including the blank paragraph boundary.

The JavaScript regular-expression character escape reference explains the four-hex-digit Unicode form. With regular-expression mode off, typing this spelling searches for a literal backslash and letters instead of the U+00A0 character.

Distinguish actual spaces from reference spellings

The six-character text   is an HTML character reference spelling. It is not itself the single U+00A0 character in a plain-text field. MDN lists this correspondence in its character reference guide.

For example, the literal input Tea time receives zero replacements with this pattern. A rendered webpage may display that reference as a nonbreaking space, so text copied from the rendered page and text copied from its source can differ.

If your export contains literal references, investigate the export format using the HTML entity decoding workflow. Do not repeatedly decode or replace spellings until a preview happens to look right.

Investigate zero matches and preserve intentional gaps

A zero count can mean the copied sample now contains ordinary spaces, or that your problematic gap is another character. In particular, \u00A0 leaves U+202F unchanged. It also leaves tabs, ordinary spaces, literal escape text and line breaks unchanged.

Do not broaden the search to every whitespace character just to get a match. First check the actual character in an editor that exposes code points. If a clipboard or destination normalizes the sample, investigate that transfer separately; the expected three-count test assumes the specified U+00A0 characters arrived intact.

For a measurement such as a number followed by its unit, keeping both together may be deliberate. Select only the affected prose when the document also contains carefully typeset labels or multilingual punctuation.

Verify the result where it will be published

Compare the output with the original and check every intended gap and paragraph. Then paste the reviewed text into its destination and inspect it at a narrow width. Replacing accidental U+00A0 characters changes available break opportunities; it does not guarantee a particular line layout or repair unrelated formatting rules.

If the destination still refuses to wrap, inspect its formatting rather than deleting more characters. Keep a saved copy of the corrected text and the replacement count. Equal character totals are expected here and do not mean that nothing changed.