What Are Zero-Width Characters?
For software developers, database administrators, and DevOps engineers, invisible characters are notorious silent killers that break string equality checks, crash JSON parsers, and produce mysterious compiler syntax errors.
Unicode defines several control characters intended for word wrapping, bidirectional text shaping, or document byte-order identification. When these slip into copy-pasted code or serialized payloads, traditional ASCII assumptions fail catastrophically.
| Character Name | Codepoint | UTF-8 Bytes | Common Source |
|---|---|---|---|
| Zero-Width Space (ZWSP) | U+200B | E2 80 8B | ChatGPT, Claude, HTML renderers |
| Byte Order Mark (BOM) | U+FEFF | EF BB BF | Windows Notepad, UTF-8 text streams |
| Non-Breaking Space (NBSP) | U+00A0 | C2 A0 | Rich-text editors, Web browsers |
| Zero-Width Non-Joiner (ZWNJ) | U+200C | E2 80 8C | Complex script ligatures |
How to Strip Zero-Width Spaces in Production Code
If you are building backend APIs, sanitizing customer form submissions, or preprocessing training datasets, here are production-ready snippets in JavaScript/TypeScript and Python:
export const stripInvisibleChars = (str: string): string => {
return str.replace(/[\u200B-\u200D\uFEFF\u00AD\u2060]/g, "");
};import re
def strip_invisible_chars(raw_text: str) -> str:
# Strip ZWSP, ZWNJ, ZWJ, BOM, and soft hyphens
pattern = re.compile(r"[\u200b-\u200d\ufeff\u00ad\u2060]")
return pattern.sub("", raw_text)
Instant Zero-Setup Debugging
Rather than writing custom one-off scripts for ad-hoc debugging, use our dedicated in-browser Invisible Character Remover utility. It highlights invisible codepoints with high-contrast colored badges and calculates precise byte-level overhead.
"What you cannot see in your editor can still break your parser. Explicit byte-level inspection is the only true defense against phantom unicode bugs."
— Developer Tools Team, Text Cleaner AI