Detect whitespace and hidden characters in text
How whitespace and hidden-character detectors work, what they reveal versus remove, and when cleaning invisible Unicode changes meaning or breaks text.
The short answer: is a hidden-character detector right for your task?
A whitespace character detector helps when two strings look identical but don't match, when a value fails validation, when a line breaks oddly, or when you suspect text contains invisible formatting or direction controls. Its main benefit is that it shows invisible characters by code point, so you can inspect them. The key tradeoff comes after detection. Revealing characters does no harm. Removing or replacing them in bulk can change how text renders, wraps or reads, especially emoji and scripts that rely on joiners. Clean plain text is the better choice for identifiers, code, data fields, file names and anything that will be searched, compared or validated. It is not automatically better for prose in languages or emoji sequences where those characters do real work.
What a detector actually changes
Detecting characters doesn't require changing your text. Tools generally do one or more of three things, and you need to know which one is happening:
- Visual marking: the tool shows a symbol or highlight on each special character and leaves the underlying text alone. This is a display layer, like an editor's 'show whitespace' option.
- Inline substitution: the tool rewrites the text so each hidden character becomes a visible token, such as a middle dot, an arrow or a label like [U+200B]. The stored text has changed, and if you copy it, you copy the tokens.
- Removal or normalization: the tool deletes selected characters or replaces them with an ordinary space (U+0020). This changes the stored text, and it is the step that can alter meaning or rendering.
Before you rely on any output, check which of these the tool performs. A highlighted view that looks clean is not the same as cleaned text. A cleaned result is not proof that nothing meaningful was removed.
Characters worth knowing
| Code point | Name | Typical role | Effect of removing or replacing |
| U+0009 | Character tabulation (tab) | Indentation, column alignment | Changes alignment; can break tab-separated data or tab-sensitive files |
| U+000D U+000A | Carriage return + line feed | Windows-style line ending | Converting to LF alone changes byte content; usually harmless for reading, but it matters for diffs and checksums |
| U+00A0 | No-break space | Keeps words, or a number and its unit, together | Allows unwanted line breaks; may make previously failing matches succeed |
| U+202F | Narrow no-break space | Thin non-breaking gap used in some typographic conventions | Same as above, plus a visible width change |
| U+2000 to U+200A | Fixed-width spaces (en, em, thin, hair and others) | Typographic spacing | Width changes; usually safe to normalize in data fields |
| U+3000 | Ideographic space | Full-width space in CJK text | Changes spacing in East Asian layouts |
| U+200B | Zero width space | Marks an optional line-break point without visible space | Long strings may stop wrapping where intended; otherwise often safe to remove |
| U+200C | Zero width non-joiner | Prevents letters from joining, for example in Persian | Can change the visible spelling of words |
| U+200D | Zero width joiner | Joins emoji into sequences; affects joining in some scripts | Splits combined emoji into separate glyphs |
| U+2060 | Word joiner | Prevents a line break without adding space | Allows breaks where none were intended |
| U+FEFF | Zero width no-break space / byte order mark | Byte order mark at the start of a file; deprecated as an inline joiner | Usually safe to remove inside text; at the start of a file, some software expects it and some rejects it |
| U+00AD | Soft hyphen | Hyphenation hint shown only at a line break | Loses hyphenation opportunities |
| U+FE0E, U+FE0F | Variation selectors 15 and 16 | Request text-style or emoji-style display | Symbol may switch between text-style and emoji-style display |
| U+2028, U+2029 | Line separator, paragraph separator | Unicode line and paragraph breaks | Line structure changes; some environments handle them inconsistently |
A good detector reports characters by code point, not only by appearance, because several of these look identical or look like nothing at all. It also helps if the tool reports Unicode general categories. Separators (Zs, Zl, Zp), format characters (Cf) and control characters (Cc) cover most of the cases above. A tool that only searches for spaces and tabs will miss zero-width and directional characters, and those are usually the ones causing confusion.
Directional controls: when text looks reversed but isn't
'Reverse' means two different things here. Reversing text as a transformation changes the order of the stored characters. Bidirectional control characters leave the stored order alone and change only the display order. The right-to-left override (U+202E), for example, makes the characters after it display right to left until the override is closed or the paragraph ends. The result can look reversed or mirrored, but copying, searching and comparing still work on the original order.
The relevant controls are:
The left-to-right and right-to-left marks (U+200E, U+200F).
The embeddings and overrides (U+202A to U+202E).
The isolates (U+2066 to U+2069).
They have legitimate uses in mixed-direction text, such as Arabic or Hebrew mixed with Latin names or numbers. They have also been documented as a way to make source code display differently from how a compiler reads it, an issue publicized as 'Trojan Source.' A detector used on code, file names or other security-sensitive text should therefore flag directional controls explicitly instead of rendering them silently.
There is also a separate effect. In right-to-left runs, paired characters such as parentheses are drawn with mirrored glyphs. This is a rendering behavior, not a character change, so a detector won't flag it and shouldn't.
When cleanup changes meaning
Stripping every invisible character is the most common way a cleanup goes wrong. Typical consequences:
- Emoji sequences joined with U+200D, such as some family and profession emoji or the rainbow flag, fall apart into separate emoji.
- Subdivision flags, such as those for England, Scotland and Wales, are built from invisible tag characters in the U+E0000 block. A tool that removes all format characters will break them.
- Removing U+FE0F can make a symbol fall back to text-style display, depending on the font and platform.
- In Persian and some other scripts, U+200C controls whether adjacent letters join. Removing it changes the visible spelling.
- Replacing no-break spaces with ordinary spaces lets lines break between a number and its unit, or inside names and dates that were meant to stay together.
- Removing a byte order mark from the start of a UTF-8 file is usually fine, but some older software uses it to detect the encoding.
- Crude scripts that delete every non-ASCII or 'non-printing' character can strip accents and combining diacritics along with the intended targets.
The safer approach is selective. Decide which characters are wrong for the destination, remove or replace only those, and keep a copy of the original. For data fields, identifiers and code, removing zero-width and directional characters is usually what you want. For prose, social posts and multilingual text, review each hit individually.
Comparing two texts at the character level
Hidden characters often come to light because two strings that look the same fail to match. A line-level or word-level diff may report a difference without showing where it is, because the differing character has no visible width. A character-level comparison that shows code points at the point of difference is more useful. Common culprits include:
A no-break space in place of a regular space.
A trailing space or tab.
A zero-width space carried over from copied web content.
CRLF versus LF line endings.
A byte order mark at the start of one file.
Unicode normalization is a related but separate check. An accented letter can be stored as one precomposed code point or as a base letter plus a combining mark. Both look the same and neither is hidden, but they compare as different strings. If a comparison still fails after you account for whitespace, the next step is to normalize both sides (for example to NFC) before comparing. Lookalike letters from other scripts, such as Cyrillic letters that resemble Latin ones, are outside what a whitespace detector is designed to find. They need a separate confusables check.
Checking text without a dedicated tool
If you'd rather not paste text into a web tool, a short script can list every space, control and format character along with its position and name. This Python example uses only the standard library:
import unicodedata
text = "price\u00a0100\u200b"
for i, ch in enumerate(text):
if ch.isspace() or unicodedata.category(ch) in ("Cc", "Cf", "Zs", "Zl", "Zp"):
name = unicodedata.name(ch, "<unnamed>")
print(i, f"U+{ord(ch):04X}", name)
For the sample string it prints the following. Variation selectors fall in a different category (Mn), so add them to the check if emoji display matters for your text.
5 U+00A0 NO-BREAK SPACE
9 U+200B ZERO WIDTH SPACE
On systems with GNU grep built with PCRE support and a UTF-8 locale, the pattern below reports lines that contain common zero-width, directional and no-break characters. It is a quick screen, not a complete check, and other grep implementations may not support this syntax:
grep -nP '[\x{00A0}\x{200B}-\x{200F}\x{202A}-\x{202E}\x{2060}\x{2066}-\x{2069}\x{FEFF}]' file.txt
Many code editors can also render whitespace and highlight invisible or ambiguous Unicode characters. Coverage of zero-width and directional characters varies, so check your editor's documentation for what it actually flags.
Readability and usability after copying or sharing
Whether the result stays usable depends on which mode the tool used.
Highlighted view: copying should return the original text, hidden characters included, which isn't enough if you meant to clean it. Whether it actually does depends on how the tool builds the view. To check, paste into a plain editor and compare the length or code points.
Substituted view: the visible tokens travel with the copy and must be removed before the text is used anywhere real. Treat this view as a diagnostic, not a finished result.
Cleaned output: this is ordinary text and copies as such, but it carries whatever changes the cleanup made.
Hidden characters left in place cause problems that are easy to miss. A zero-width character inside a word changes the stored sequence. A plain search for that word, a username check or a spreadsheet lookup can then fail even though the text looks right. Directional controls can make the displayed order differ from the stored order, which affects editing: the cursor may move unexpectedly, and selections may not cover what they appear to.
Assistive technology behavior varies by screen reader, voice, browser and settings. Some characters may be ignored; others may be announced, or may change how a word is split or pronounced. No tested results for specific screen readers were available for this review, so no claim is made about any named product. If text is going into an accessible interface, test it with the assistive technology your audience uses, or remove characters that serve no purpose for the content.
You need a plain-text equivalent, meaning text with only ordinary spaces and standard line breaks, whenever the destination compares, validates, indexes or executes the text. That includes code, configuration, file names, form fields, identifiers, data imports and search-sensitive content. For readable prose that relies on joiners, no-break spaces or directional marks, keep those characters and remove only the ones that are clearly accidental.
What to check before trusting a detector
- Does it identify characters by code point and name, not just with a generic marker?
- Does it cover zero-width, format and directional characters, not only spaces, tabs and line breaks?
- Does it make clear whether the output is a highlighted view, a substituted view or cleaned text?
- Can you choose which characters to remove, instead of stripping everything?
- Does it handle emoji sequences and combining marks correctly when it reports positions and counts?
- Where is the text processed? You can't tell from a tool's design or marketing whether it works locally in the browser or sends text to a server. Look for an explicit, specific statement, and avoid pasting sensitive text if there isn't one.
Limits of this review
No specific detector tools were tested for this article. No product features, privacy practices, or rendering results for particular apps, browsers or screen readers are claimed. The character behaviors described here come from how Unicode defines these characters. Actual display depends on fonts, platforms and software, so verify the result in your own destination before relying on cleaned or annotated text.