Invisible characters in text: what they are and how to remove them
Two strings look identical but will not match. A search finds nothing, though the word is on screen. A character count is higher than it should be. Invisible characters are usually the reason.
The usual suspects
- Zero-width space (U+200B): takes up no room, and marks a spot where a line may break.
- Zero-width non-joiner and joiner (U+200C and U+200D): control how letters connect, and hold emoji sequences together.
- Word joiner (U+2060): stops a line from breaking at that spot.
- Byte order mark or zero-width no-break space (U+FEFF): sometimes written at the very start of a text file.
- Soft hyphen (U+00AD): shows a hyphen only if the word has to break at the end of a line.
- Left-to-right and right-to-left marks (U+200E and U+200F) and the embedding controls (U+202A to U+202E): steer the direction of mixed-direction text.
Where they come from
Web pages and apps add them to control how long words wrap, so copying text out of a page can bring them along. Word processors insert soft hyphens. A file saved as UTF-8 with a byte order mark begins with U+FEFF. Chat apps, editors and PDF viewers can add others when they convert text. You rarely type them yourself, which is why they come as a surprise.
Symptoms
- A search for a word finds nothing even though it is clearly there.
- Two lines that look the same are treated as different, so duplicates are not removed or a spreadsheet lookup fails.
- A character count is higher than the number of visible characters.
- A program stops with an "unexpected character" error on a line that looks fine.
- A link or a form field rejects pasted text.
How to find them
Paste the text into the Character Counter and compare the count with what you can see, or count a short piece by hand. A mismatch points to hidden characters. The Remove Zero-Width Characters tool is more direct: it tells you how many hidden characters it found before it removes them. In code, a pattern such as [\u200B-\u200D\u2060\uFEFF] finds most of them.
Removing them
- Paste the text into the Remove Zero-Width Characters tool. It removes the zero-width and joiner characters, the word joiner, the byte order mark, the soft hyphen, and the direction marks and embedding controls.
- Press "Use result as input" and run the Remove Extra Spaces tool if odd gaps remain. Non-breaking spaces are different from zero-width characters and are handled there.
- Copy the clean text.
When not to remove them
Some of these characters are doing a job. The joiner holds emoji such as families and some flags together, and removing it splits them into separate pictures. In Persian and several other scripts, the non-joiner controls how letters connect, and text that mixes left-to-right and right-to-left scripts may need the direction marks to display in the right order. For plain English text, removing them is safe. For other languages and emoji-heavy text, check the result.
Privacy
The tools run in your browser, so the text you check is not sent anywhere.