How to see hidden characters in any text
For a one-off mystery, a hex dump settles the argument: pbpaste | hexdump -C. For code, turn on your editor's invisibles highlighting and leave it on. For a string you cannot paste anywhere, a targeted regex search finds the usual suspects.
You cannot fix what you cannot see. When a string misbehaves, when a search will not match, a form rejects clean-looking input, or a diff shows a change with nothing visibly different, the first step is making the invisible visible. Here are four ways to do that.
1. Your code editor's invisibles mode
Every serious editor can render invisible characters. Most hide the setting.
- VS Code highlights many invisible and confusable characters out of the box via
editor.unicodeHighlight, drawing a box around characters likeU+200B. It is the fastest "wait, what is that" detector in daily use. - Sublime Text shows them via
draw_unicode_white_space. - BBEdit has View, then Text Display, then Show Invisibles.
- JetBrains IDEs render a highlighted escape for non-ASCII spaces in recent versions.
Editor rendering is ideal for code, because you stay exactly where the bug is.
2. A regex sweep
If you suspect a specific character, search for it directly. Most find dialogs accept Unicode escapes in regex mode, which avoids the awkward problem of typing an invisible character into a search box:
That one class catches the usual suspects: the zero-width space, both joiners, the word joiner, the byte-order mark, the non-breaking and narrow no-break spaces, and the soft hyphen. It will not catch everything, since Unicode has hundreds of format characters, but it finds the ones responsible for most real breakage.
3. A hex dump
The ground truth. On macOS, pipe the clipboard through hexdump:
A zero-width space appears as the UTF-8 bytes e2 80 8b, a narrow no-break space as e2 80 af, a non-breaking space as c2 a0. Nothing can hide from a byte listing, which makes this the method of record when you need certainty and the least convenient one for everyday use.
4. An online inspector
Paste-in web tools list every code point in a string with its name. They are quick and require nothing installed. Two caveats. First, you are pasting your text into someone else's website, which is a strange move if the text is private. Some process locally in the browser; verify before trusting. Second, they tell you what is there. Removing it and re-copying is still on you, every single time.
Which one should you use?
| Situation | Use |
|---|---|
| A one-off mystery string | Hex dump |
| Code and configs, all day | Editor invisibles, permanently on |
| Hunting a specific character | Regex sweep |
| No terminal, no editor | Online inspector, carefully |
All four are diagnosis. If you find yourself diagnosing weekly, the honest conclusion is that invisible characters are not rare events, they are a constant low-level leak in copy and paste itself, and the cure is to treat the clipboard rather than the symptom. See the full field guide for what, exactly, is leaking.
Text cleaning is coming next to tdy.
tdy is a Mac menu-bar app that already tidies every link you copy. Catching invisible characters at the moment you copy, with nothing to paste into and nothing to remember, is the next upgrade. One email when it ships, nothing else.
Join the launch list