Remove Non-Printable Unicode Characters: What Stripping Changes and When It Is Safe

Removing non-printable Unicode characters can fix search, matching and parsing problems, but it can also break emoji, scripts and line breaks.

Text copied from web pages, chat apps, PDFs and word processors often carries characters you cannot see: zero-width spaces, byte order marks, directional marks, soft hyphens and stray control codes. Stripping them is a common cleanup step, but it is not neutral. Some invisible characters are noise, while others hold emoji together, shape letters in certain scripts or keep mixed-direction text in the right order. This review explains what removal actually does, where it helps, and where a blanket filter does damage.

Is removing non-printable characters right for your use?

For identifiers, usernames, search terms, spreadsheet cells, configuration values, source code and other data that must compare or match exactly, removing invisible characters is usually the right call. The main benefit is that two strings which look identical will actually be identical, so lookups, deduplication, parsing and validation stop failing for reasons nobody can see.

The decisive tradeoff is that "non-printable" is not a single, well-defined set. A filter broad enough to catch every stray character will also remove line breaks, tabs, emoji joiners and characters that some languages need. For multilingual prose, emoji-heavy social text, or anything containing Arabic, Hebrew, Persian or Indic scripts, a targeted cleanup that inspects first and removes only known-unwanted characters is preferable to a blanket strip.

A plain-text version, fully stripped of invisible characters, is the better target when the text will be used as data rather than read as prose: keys, filenames, slugs, codes, form values and anything fed into search or comparison logic.

What "non-printable" actually covers

Unicode assigns every character a general category. Most tools that remove non-printable characters work from some combination of the following categories, and the choice of which ones to include determines what gets lost.

  • Cc (control): the old ASCII and Latin-1 control codes, including NUL and escape, but also tab, line feed and carriage return.
  • Cf (format): invisible characters that influence layout or rendering, such as zero-width space, zero-width joiner and non-joiner, soft hyphen, word joiner, the byte order mark, directional marks, bidirectional embedding, override and isolate controls, and tag characters.
  • Zs, Zl, Zp (separators): visible-as-whitespace characters such as the ordinary space, the no-break space and various fixed-width spaces, plus the line and paragraph separators.
  • Co (private use): code points with no standard meaning, often used by icon fonts and vendor-specific glyphs.
  • Cn (unassigned): code points not yet assigned in the Unicode version your software knows about.

The word "non-printable" also gets used loosely for whitespace look-alikes such as the no-break space, and for variation selectors, which are technically combining marks rather than format characters. Some invisible-character removers target these, others do not, so a tool's description alone does not tell you which set it removes.

What removal changes: stored characters, not appearance

Invisible characters are real code points stored in the text. They survive copy and paste in most environments, they count toward string length, and they participate in comparisons. Removing them changes the stored text itself. This is different from styling or CSS, which only changes how text is displayed; hiding a character visually does not remove it, and removing it is not a presentation choice that can be toggled back.

Because the change is to stored characters, the effect can be invisible in one case and dramatic in another. The table below shows commonly encountered characters and what typically happens when they are removed.

Character | Code point | Category | Typical role | Effect of removing
Zero-width space | U+200B | Cf | Line-break hint; often a paste artifact | Usually harmless; may affect line breaking in languages written without spaces
Byte order mark / zero-width no-break space | U+FEFF | Cf | Encoding signature at file start | Usually harmless and often desirable
Soft hyphen | U+00AD | Cf | Optional hyphenation point | Usually harmless; loses hyphenation hints
Word joiner | U+2060 | Cf | Prevents a line break | Usually harmless; text may wrap differently
Zero-width joiner | U+200D | Cf | Joins emoji sequences; shapes some Indic scripts | Can split emoji and alter rendering of words
Zero-width non-joiner | U+200C | Cf | Prevents joining in Persian and other scripts | Can change how words are written and read
Left-to-right and right-to-left marks | U+200E, U+200F | Cf | Fix display order around neutral characters | Punctuation and numbers may display in the wrong place
Bidirectional overrides and isolates | U+202A to U+202E, U+2066 to U+2069 | Cf | Force or isolate display direction | Visual order can change; may be wanted or unwanted
Tag characters | U+E0020 to U+E007F | Cf | Subdivision flag emoji sequences | Flag emoji such as England or Scotland fall back to a generic flag
Variation selector-16 | U+FE0F | Mn | Requests emoji-style presentation | Some symbols may render as monochrome text glyphs
Tab, line feed, carriage return | U+0009, U+000A, U+000D | Cc | Layout and line structure | Lines run together; tab-separated data breaks
No-break space | U+00A0 | Zs | Keeps words together | Words can merge if deleted rather than replaced with a normal space

Illustrative examples

The following examples describe how the code points relate to one another; they are not results from testing a particular tool or platform.

  • A word with a hidden break: "pass" + U+200B + "word" displays like "password" but is a different, longer string. Removing U+200B makes it match.
  • A family emoji: man (U+1F468), ZWJ, woman (U+1F469), ZWJ, girl (U+1F467). Removing the two ZWJ characters leaves three separate emoji instead of one combined glyph.
  • A heart: U+2764 followed by U+FE0F. Removing the variation selector may cause the heart to appear as a plain text symbol on some systems.
  • Persian text: the ZWNJ in a word such as "می‌خواهم" keeps the prefix visually separate from the rest of the word. Removing it causes the letters to connect, which changes how the word is written.

How this relates to reverse, mirror and "font" text

Removing invisible characters does not undo text styling. "Fancy font" text built from mathematical alphanumeric symbols or other look-alike letters consists of visible characters, so it passes through a non-printable filter unchanged; converting it back to ordinary letters is a separate step, typically compatibility normalization (NFKC) or a character mapping.

Reversed or mirrored text is a different case. Some tools reverse the stored order of characters, which removing invisible characters does not affect. Others leave characters in their original order and insert a right-to-left override so that the text displays backwards. Stripping that override reverts the visual order to the stored order, which means "cleaning" such text can appear to un-reverse it. If text looks different after cleanup, checking for bidirectional controls is a good first step.

Inspect before you remove

Because the same filter can be harmless on one string and destructive on another, the safer workflow is to list what is actually present, decide what to keep, and then remove only the rest. A short script can report every invisible or whitespace character by code point, category and name.

import unicodedata

def report_invisible(text):
    for i, ch in enumerate(text):
        cat = unicodedata.category(ch)
        if (cat[0] in "CZ" or cat == "Mn") and ch != " ":
            name = unicodedata.name(ch, "<unnamed>")
            print(f"{i:>5}  U+{ord(ch):04X}  {cat}  {name}")

Once you know what is present, an allowlist approach keeps structural and script-dependent characters while removing the rest of the control and format range. The keep set below is a starting point, not a universal answer; adjust it to the languages and content you handle.

import unicodedata

KEEP = {
    "\t", "\n", "\r",      # layout
    "\u200c", "\u200d",    # ZWNJ, ZWJ (scripts and emoji)
    "\u200e", "\u200f",    # LRM, RLM (mixed-direction text)
}

def strip_invisible(text):
    return "".join(
        ch for ch in text
        if ch in KEEP or unicodedata.category(ch) not in ("Cc", "Cf")
    )

The equivalent in JavaScript uses Unicode property escapes, which require the u flag:

const KEEP = new Set(["\t", "\n", "\r", "\u200C", "\u200D", "\u200E", "\u200F"]);

function stripInvisible(text) {
  return text.replace(/[\p{Cc}\p{Cf}]/gu, (ch) => (KEEP.has(ch) ? ch : ""));
}
  • These filters still remove tag characters, so subdivision flag emoji will degrade; add the tag range to the keep set if that matters.
  • They leave variation selectors, private-use characters and no-break spaces alone. Handle those separately if your use case requires it, for example by replacing no-break spaces with ordinary spaces rather than deleting them.
  • Avoid relying on Python's str.isprintable() as a cleanup filter. Its documented definition treats all "Other" and "Separator" characters except the ASCII space as non-printable, so it would also remove newlines, tabs, no-break spaces and private-use characters.
  • Filters that drop unassigned (Cn) code points depend on the Unicode version built into your language runtime. A runtime with older Unicode data can treat newly added characters, including recent emoji, as unassigned and delete them.

Will the cleaned text stay readable and usable?

For copying and sharing, cleaned text is generally more predictable than the original, because there are fewer hidden characters for a destination to interpret differently. The risks come from what was removed, not from the cleanup itself: lost line breaks, merged words where a no-break space was deleted, split emoji, altered letter joining, and mixed-direction text whose punctuation or numbers move after directional marks are stripped.

Search and editing benefit most. A hidden zero-width character inside a word prevents it from matching a search for that word, makes string comparisons fail, and can cause a cursor to appear stuck when stepping through text. Removing such characters restores normal matching and editing. Bidirectional override and isolate characters in source code are a known security concern, because they can make code display in an order different from how it is executed; flagging or removing them in code is a widely recommended practice.

Accessibility effects need to be checked in your own environment. Screen readers and other assistive technology handle invisible characters differently, and the evidence available for this review does not include tests of any specific screen reader, browser or platform. As a general principle, text that relies on unusual characters to look a certain way, such as reversed, mirrored or styled text, should be accompanied by a plain-text equivalent wherever it needs to be read aloud, searched or edited by others.

Evaluating an online remover

No specific tool was tested for this review, so no tool can be recommended or ranked here. When judging one, look for a clear statement of which characters or categories it removes, a preview that shows removed characters by code point rather than just the output, and options to keep line breaks, joiners and directional marks. Run it on a small sample containing emoji sequences and any scripts you work with, then compare the code points before and after rather than relying on how the output looks.

A tool's appearance or marketing does not indicate whether pasted text is sent to a server or retained. If the text is sensitive, prefer a local script like the ones above, or confirm the tool's data handling from its own documentation.

Bottom line

Removing non-printable Unicode characters is a sound default for data that must match, parse or validate, and a risky default for multilingual prose and emoji. Inspect what is present, keep line breaks, tabs, joiners and directional marks unless you know they are unwanted, and verify results by code point. Where styled, reversed or mirrored text is involved, remember that stripping invisible characters will not restore plain letters and may change visual order, so keep a plain-text version for anything that must stay readable and searchable.