Detect special characters in a string
How to check a string for special, invisible and look-alike characters by code point, what inspection reveals, where online checkers fall short, and when plain text is safer.
A string can look ordinary and still contain characters you didn't expect: a no-break space instead of a regular one, a zero-width character between letters, a Cyrillic letter that looks Latin, or a direction control that changes how the text displays. To detect special characters reliably, you have to stop trusting what the text looks like and examine its code points. This guide covers what inspection shows, how to do it in code or with an online checker, and where its limits are.
Short answer: is code point inspection the right approach?
Code point inspection is the right approach if you need to know exactly what a string contains. Typical cases are debugging a failed comparison, validating input, cleaning pasted data, reviewing text before publishing, or checking the output of a stylized-text, reverse or mirror tool. Its main benefit is certainty. Each character is listed by its Unicode code point and name, so nothing hides behind similar-looking glyphs. The tradeoff is that inspection only reports what is there. It doesn't decide which characters are acceptable, and any cleanup step that follows can change meaning if it is applied without care. If you only need ordinary readable text, and the content comes from a source you control, plain typed text with no inspection step is usually enough. Once text has been through a styling tool, inspection is how you confirm it is still plain text.
What counts as a "special character"
The phrase means different things in different contexts, and a checker built for one meaning can miss another. Decide which meaning you need before choosing a method:
- Punctuation and symbols: anything other than letters and digits, as in password rules. A simple pattern such as [^A-Za-z0-9] covers this, but it also flags accented letters and every non-Latin script.
- Non-ASCII characters: anything outside the basic 128-character ASCII range. This matters for legacy systems, identifiers and some file formats.
- Invisible and control characters: zero-width characters, format controls, no-break spaces, soft hyphens and line separators. These render as nothing, or as an ordinary space, but they change how text compares, wraps or searches.
- Look-alike characters (homoglyphs): characters from another script or symbol block that resemble common letters, such as Cyrillic а (U+0430) alongside Latin a (U+0061).
- Stylized "font" characters: letters from blocks such as Mathematical Alphanumeric Symbols or Fullwidth Forms. Generator tools use them to imitate bold, script or wide fonts.
What inspection does and does not change
Inspection is read-only. It breaks a string into its code points and reports each one's hexadecimal value, official Unicode name and general category, for example Cf for format characters or Zs for space separators. The stored text is unchanged. This differs from the transformations people often want to check. Character substitution, used by "fancy font" generators, stores different code points that only resemble the originals. Reversal reorders the stored characters. Bidirectional controls and CSS styling change how text is displayed without changing which letters are stored. Inspection is the way to tell these apart. A change to stored characters shows up as different code points, while a change that is purely visual leaves the code points as they were.
Characters worth looking for
| Code point | Name | Category | Why it matters |
| U+00A0 | NO-BREAK SPACE | Zs | Looks like a space but fails equality checks and simple space splitting |
| U+200B | ZERO WIDTH SPACE | Cf | Invisible; breaks search, matching and identifiers |
| U+200C | ZERO WIDTH NON-JOINER | Cf | Invisible; meaningful in some scripts, unwanted in others |
| U+200D | ZERO WIDTH JOINER | Cf | Joins emoji sequences; invisible when stray |
| U+2060 | WORD JOINER | Cf | Invisible; prevents line breaks |
| U+FEFF | ZERO WIDTH NO-BREAK SPACE (byte order mark) | Cf | Often left at the start of files or pasted text |
| U+00AD | SOFT HYPHEN | Cf | Usually invisible unless a line breaks at it |
| U+200E / U+200F | LEFT-TO-RIGHT MARK / RIGHT-TO-LEFT MARK | Cf | Affect display direction of surrounding text |
| U+202E | RIGHT-TO-LEFT OVERRIDE | Cf | Forces right-to-left display; can make stored and displayed order differ |
| U+2066–U+2069 | Directional isolates | Cf | Same concern as overrides in source code and filenames |
| U+2028 | LINE SEPARATOR | Zl | Acts as a line break in some environments and not in others |
| U+FE0F | VARIATION SELECTOR-16 | Mn | Requests emoji-style display; invisible on its own |
| U+0430 | CYRILLIC SMALL LETTER A | Ll | Visually identical to Latin a in many fonts |
| U+2019, U+2013, U+2212 | Right single quotation mark, en dash, minus sign | Pf, Pd, Sm | Typographic substitutes for ', - and - that break code and exact matching |
How to check special characters in code
Python's standard library can list every code point with its name and category:
import unicodedata
def inspect(s):
for ch in s:
print(f"U+{ord(ch):04X} {unicodedata.category(ch)} {unicodedata.name(ch, '<unnamed>')}")
inspect("cafe\u0301\u00a0x\u200b")
For that input, the output lists seven code points even though the string appears as "café x":
U+0063 Ll LATIN SMALL LETTER C
U+0061 Ll LATIN SMALL LETTER A
U+0066 Ll LATIN SMALL LETTER F
U+0065 Ll LATIN SMALL LETTER E
U+0301 Mn COMBINING ACUTE ACCENT
U+00A0 Zs NO-BREAK SPACE
U+0078 Ll LATIN SMALL LETTER X
U+200B Cf ZERO WIDTH SPACE
To flag only the suspicious characters along with their positions, filter for anything that is non-ASCII or non-printable. Tabs and newlines are non-printable, so they will be flagged as well. Exclude them explicitly if they are expected.
def flag(s):
return [(i, f"U+{ord(ch):04X}", unicodedata.name(ch, "<unnamed>"))
for i, ch in enumerate(s)
if not ch.isascii() or not ch.isprintable()]
In JavaScript, iterate with for...of, which steps through code points rather than UTF-16 units. Regular expressions with the u flag can match by Unicode property. For example, /\p{Cf}/u finds format characters and /[^\x20-\x7E]/u finds anything outside printable ASCII. Python's built-in re module does not support \p{...} property classes. The third-party regex module does.
for (const ch of str) {
const cp = ch.codePointAt(0).toString(16).toUpperCase().padStart(4, "0");
console.log(`U+${cp}`);
}
Code points, code units and visible characters
There are three ways to count characters, and they give different answers. In JavaScript, "👍".length is 2 because the emoji is stored as two UTF-16 code units, although it is a single code point. A family emoji such as 👨👩👧 is five code points: three people joined by two U+200D zero-width joiners. It is still read as one symbol. Likewise, é can be one code point (U+00E9) or two (e followed by U+0301). A good inspector shows code points. When you need to work with what a reader perceives as one character, use grapheme segmentation, such as Intl.Segmenter in JavaScript.
The distinction is important when you check the output of a reverse-text tool. A tool that reverses code points one at a time moves a combining accent onto a different letter. It also breaks joined emoji into separate figures or leaves joiners stranded. Inspecting the result shows whether the tool reversed graphemes or raw code points.
Detecting versus cleaning
Detection should come before any cleanup, and the two should stay separate steps. Unicode normalization handles some cases. NFC composes e plus a combining accent into é. NFKC also folds compatibility characters, so fullwidth A and mathematical bold 𝐀 become A, and a no-break space becomes a regular space. Normalization does not remove zero-width spaces. It also does not convert Cyrillic letters to Latin ones; catching look-alikes requires confusable detection as described in Unicode's security mechanisms (UTS #39). Removing characters is not always safe. Zero-width joiners hold emoji sequences together, and zero-width non-joiners are part of correct spelling in some languages. Stripping every Cf character can therefore damage legitimate text. Review what was flagged before deleting anything.
Using an online checker
A browser-based tool for checking special characters in a string is convenient for one-off checks. Before relying on one, confirm three things. It should show code points and names, not just highlight "weird" characters. It should handle characters outside the Basic Multilingual Plane, such as emoji and mathematical letters, without splitting them. And it should not alter the text itself, for example by trimming whitespace on paste. A tool's appearance or marketing tells you nothing about whether it sends text to a server or keeps it. Unless the tool documents that processing happens locally, do not paste passwords, tokens, personal data or confidential text into it. Use a local script for those.
Will results survive copying and sharing?
Text can change between the place you inspected it and the place it ends up. Editors, chat apps, form fields and content systems may strip some invisible characters, convert no-break spaces, replace straight quotes with typographic ones, or normalize text. Others leave everything untouched. Behavior differs between destinations and sometimes between versions of the same app, so a clean result in one place says nothing about another. If exact content matters, inspect the text again at its final destination, or as close to it as you can get.
Hidden and substituted characters also affect accessibility, search and editing. Stylized letters from symbol blocks are separate characters, not formatting. Screen readers may announce them by symbol name, spell them out or skip them, depending on the software and its settings. Search engines and site search may not match them to ordinary words. Zero-width characters can split a word so that search, spellcheck or find-and-replace treats it as two words. Bidirectional controls can make the displayed order differ from the reading order that assistive technology and copy/paste follow. Wherever text has to be read aloud, searched, edited, used as an identifier or compared, provide a plain-text equivalent. Use stylized or controlled text only as decoration, if at all.
Evidence gaps
This guide is based on general Unicode behavior and standard library features. It does not include tests of specific online checkers, apps, platforms or screen readers, and it makes no claims about how any named destination handles invisible or stylized characters. Before relying on a particular tool or destination, run a small test of your own. Paste a string containing known characters, such as a no-break space, a zero-width space, a combining accent and a joined emoji, and confirm what comes out.