textscrubr
Home / Blog / Developers

How to Find Invisible Characters Breaking Your Code

Developers2 min readUpdated 2026-06-23
To find invisible characters breaking your code, enable whitespace and non-breaking-space highlighting in your editor, search for code points like \u200B and \u00A0 with regex, or paste the snippet into a cleaner that reports them. Then strip them, since a zero-width or non-breaking character can cause an error with no visible cause.

Few bugs are as maddening as code that looks correct but will not run. Often the culprit is a character you cannot see. Here is how to hunt it down.

How an invisible character breaks code

A zero-width space inside a variable name makes two identifiers that look identical actually different. A non-breaking space instead of a regular space breaks indentation in Python or trips a parser. A BOM at the top of a file stops a script from running. In every case, the editor shows nothing wrong, because the character is invisible.

These sneak in when you copy code from a web page, a chat tool, a PDF, or documentation, where invisible characters were used for formatting.

Method 1: turn on editor highlighting

Method 2: search by code point with regex

If your editor supports regex search, hunt the usual suspects directly:

\u200B    zero-width space
\u00A0    non-breaking space
\uFEFF    byte-order mark
\u200D    zero-width joiner

Search for each and you will land right on the offending character.

Method 3: paste it into a cleaner

For a fast check without editor setup, paste the snippet into a cleaner that reports hidden characters. textscrubr scans for invisible characters and shows you a count of each, so you can confirm whether your "impossible" bug is actually a zero-width space hiding in a string or identifier. It strips truly invisible characters from code while leaving your spacing, indentation, and punctuation alone, so it does not change the code itself.

Method 4: check the bytes

In a quick script, compare what you see to the byte or code-point length. If a line is longer than it looks, something invisible is padding it. You can also print the code points of a suspect string to see exactly what is there.

Prevent it

When copying code from any styled source, run it through a cleaner or paste as plain text first. Make it a habit for snippets from documentation and chat tools, where invisible characters are most common, and you will save yourself the next hour-long hunt for a bug that was never visible.

Scrub this text in one click

textscrubr strips the hidden characters, em dashes, and double spaces, and keeps your lists, headings, and code exactly where you put them. Free, and it runs entirely in your browser.

Clean my text free →

Frequently asked questions

Can an invisible character really break my code?

Yes. A zero-width space in an identifier, a non-breaking space in indentation, or a BOM at the top of a file all cause errors that are invisible in the editor, because the character itself cannot be seen.

How do I find invisible characters in code?

Enable whitespace and non-breaking-space highlighting in your editor, search for code points like \u200B and \u00A0 with regex, or paste the snippet into a cleaner that reports hidden characters.

Will cleaning code remove my indentation?

A good cleaner removes only truly invisible characters inside code and leaves spacing, indentation, and punctuation alone, so it fixes the hidden character without changing your code.