Identify Non-Alphanumeric Characters
How to find and name non-alphanumeric characters by code point, why the definition changes the result, and what to check before stripping or replacing them.
A non-alphanumeric character is any character that is not a letter or a digit. That sounds simple until text arrives with a no-break space that looks like a normal space, an en dash that looks like a hyphen, or an accent stored as a separate mark. Identifying these characters reliably means looking at code points, not at how the text appears on screen. This review covers what a code point inspection actually tells you, where common definitions disagree, and when filtering or replacing characters is safe.
Is code point inspection the right approach for your task?
Recommendation: inspect characters by code point whenever text behaves unexpectedly, such as a search that fails to match, a validation rule that rejects visually correct input, or a string that looks identical to another but does not compare as equal. The main benefit is precision: each character is reported with a unique number and an official name, so lookalikes and invisible characters stop being guesswork.
The decisive tradeoff is that you must choose a definition of alphanumeric before the results mean anything. A rule limited to the ASCII letters A to Z, a to z and the digits 0 to 9 treats an accented letter, a Cyrillic letter or a superscript digit as non-alphanumeric. A Unicode-aware rule treats all of them as letters or numbers. Neither is wrong; they serve different purposes.
A plain ASCII allowlist is usually preferable when the text becomes an identifier that machines or people must type and compare exactly, such as usernames, file names, URL slugs or configuration keys. A Unicode-aware definition is preferable for names, prose and multilingual content, where treating every non-ASCII letter as foreign would damage meaning.
What identification actually changes, and what it does not
Inspection itself changes nothing. It reads the stored characters and reports properties defined by the Unicode Standard: the code point (written as U+ followed by hexadecimal digits), the character name and the general category. The general category is the most useful property for deciding whether a character counts as a letter or digit.
| Category group | Meaning | Example characters |
| L | Letter | U+0061 LATIN SMALL LETTER A; U+0430 CYRILLIC SMALL LETTER A |
| N | Number | U+0035 DIGIT FIVE; U+00B2 SUPERSCRIPT TWO |
| M | Mark (often combining) | U+0301 COMBINING ACUTE ACCENT |
| P | Punctuation | U+003A COLON; U+2013 EN DASH |
| S | Symbol | U+20AC EURO SIGN; U+2212 MINUS SIGN |
| Z | Separator | U+0020 SPACE; U+00A0 NO-BREAK SPACE |
| C | Other, including control and format characters | U+0009 CHARACTER TABULATION; U+200B ZERO WIDTH SPACE |
Under a Unicode-aware rule, anything outside the L and N groups is non-alphanumeric. The M group is the common trap: an accented letter can be stored either as one precomposed character or as a base letter followed by a combining mark. Both display the same way, but a character-by-character check flags the combining mark as non-alphanumeric and may strip it, turning a word into a different word.
Transformations that look like styling often turn out to be character substitution when inspected. So-called fancy fonts produced by copy-and-paste generators are usually characters from the Mathematical Alphanumeric Symbols block, such as U+1D400 MATHEMATICAL BOLD CAPITAL A. These are categorized as letters, so a Unicode-aware check accepts them while an ASCII check rejects them. Unicode compatibility normalization (NFKC) maps them back to ordinary letters, which is a useful way to recover the plain text.
Two other effects are easy to confuse with substitution. Bidirectional control characters, such as U+202E RIGHT-TO-LEFT OVERRIDE, change the order in which text is displayed without changing the stored order, so a string can look reversed while its code points are not. Reversed text produced by a generator, by contrast, stores the characters in reverse order; if it reverses code points rather than whole characters, combining marks detach from their letters and multi-code-point emoji, which are joined by U+200D ZERO WIDTH JOINER or followed by U+FE0F VARIATION SELECTOR-16, break apart. An inspector shows which of these happened.
A working example
The following Python snippet uses the standard unicodedata module to list every character that Python's isalnum method does not treat as a letter or number. The input deliberately includes a no-break space, an en dash and an accent stored as a combining mark.
import unicodedata
text = "Price:\u00a0€5 – cafe\u0301"
for ch in text:
if not ch.isalnum():
print(f"U+{ord(ch):04X}", unicodedata.category(ch), unicodedata.name(ch, "<unnamed>"))
U+003A Po COLON
U+00A0 Zs NO-BREAK SPACE
U+20AC Sc EURO SIGN
U+0020 Zs SPACE
U+2013 Pd EN DASH
U+0020 Zs SPACE
U+0301 Mn COMBINING ACUTE ACCENT
The last line shows the combining mark problem directly: the word displays as café, yet one of its code points is reported as non-alphanumeric. Normalizing the text to NFC before checking would combine the e and the accent into the single letter U+00E9 in this case, and the mark would no longer be flagged.
In JavaScript, the equivalent Unicode-aware test is a regular expression with property escapes and the u flag, which matches any character that is neither a letter nor a number:
/[^\p{L}\p{N}]/gu
Be careful with the shorthand \W or \w in regular expressions. In most engines the word class includes the underscore, so non-word and non-alphanumeric are not the same set. Whether \w covers non-ASCII letters also depends on the language and flags in use.
Will the text stay readable and usable after copying or sharing?
Non-alphanumeric characters generally survive copy and paste because they are real stored characters, not formatting. That persistence is exactly why they cause trouble later. Practical consequences to check:
- Search and matching: a query typed with an ordinary space or hyphen will not match text containing a no-break space, en dash or minus sign unless the search tool normalizes them.
- Editing: zero width and format characters are invisible, so cursor movement and deletion can behave unexpectedly around them.
- Validation: input forms may reject or silently strip characters, and the rules differ between systems.
- Reading order: bidirectional controls can make displayed text disagree with stored text, which matters for anything a person must verify, such as file names.
- Assistive technology: screen readers may announce substituted letters, symbols and emoji by name or skip them, and behavior varies by product, version and settings.
No screen reader tests or destination-specific documentation were supplied for this review, so no claim is made about how any particular app, platform or assistive technology handles these characters. Test in the actual destination, and do not treat one correct rendering as proof that others will match.
A plain-text equivalent is needed whenever the content must be searchable, accessible or machine-compared: provide the ordinary letters, digits and ASCII punctuation alongside or instead of styled or substituted characters, and remove invisible format characters that serve no purpose.
How to recognize the problem and where to find an inspection method
Clues that non-alphanumeric or lookalike characters are present: two strings look identical but fail an equality check; a word wraps or refuses to wrap unexpectedly; the character count is higher than the visible text suggests; letters look slightly bold, italic or oddly spaced in a field that should be plain; or text reads in an unexpected direction when pasted.
Verified methods that require no third-party service are the ones shown above: Python's unicodedata module and Unicode property escapes in JavaScript regular expressions. Many code editors can also display whitespace and invisible characters, though the setting name and location vary by editor and were not verified here. For standalone tools, useful search terms include Unicode character inspector, code point lookup, show invisible characters, and Unicode general category. Online tools were not reviewed; this article makes no claim about their accuracy or how they handle pasted text, so avoid pasting sensitive content into any tool whose data handling you have not checked.
Before you strip or replace anything
- Decide whether alphanumeric means ASCII only or any Unicode letter and number.
- Normalize first (NFC to combine accents, or NFKC if styled letters should become plain ones), then check.
- Decide whether the underscore and other permitted separators are allowed, rather than relying on \w.
- Review flagged characters by name before removing them; punctuation and marks often carry meaning.
- Keep the original text so a destructive cleanup can be reversed.