Hidden characters: why two values that look identical do not match
Two cells show the same email address, yet VLOOKUP says #N/A and a duplicate check keeps both. The cause is usually a character you cannot see. We tested which common trim functions remove which hidden characters: none of them removes the zero width space.
The usual suspects
| Character | Code | Unicode category | Counts as white space? |
|---|---|---|---|
| No-break space | U+00A0 | Space separator (Zs) | Yes |
| Narrow no-break space | U+202F | Space separator (Zs) | Yes |
| Figure space | U+2007 | Space separator (Zs) | Yes |
| Ideographic space | U+3000 | Space separator (Zs) | Yes |
| Zero width space | U+200B | Format (Cf) | No |
| Zero width non-joiner / joiner | U+200C / U+200D | Format (Cf) | No |
| Word joiner | U+2060 | Format (Cf) | No |
| Zero width no-break space (byte order mark) | U+FEFF | Format (Cf) | No |
| Soft hyphen | U+00AD | Format (Cf) | No |
"Counts as white space" is the Unicode White_Space property from the Unicode Character Database
(version 18.0). It matters because most "trim" functions and the \s of regular expressions follow it, more
or less. The zero width characters are not white space in Unicode: they are format characters, and Unicode marks them
Default_Ignorable_Code_Point, meaning software should not display them. So they are invisible, and most
cleaning functions leave them alone.
What trim functions actually remove: our test
We put each character before and after the letter x and ran the usual trim functions (6 October 2026: Node.js 20.20, Python 3.9.6; Excel and Google Sheets from their official documentation).
| Character | JavaScript trim() | Python strip() | Excel TRIM | Google Sheets Trim whitespace |
|---|---|---|---|---|
Normal space U+0020 | Removed | Removed | Removed | Removed |
No-break space U+00A0 | Removed | Removed | Kept | Kept |
| Narrow no-break, figure, ideographic space | Removed | Removed | Kept | Not documented |
Byte order mark U+FEFF | Removed | Kept | Kept | Not documented |
Zero width space U+200B | Kept | Kept | Kept | Not documented |
| Zero width joiners, word joiner, soft hyphen | Kept | Kept | Kept | Not documented |
Excel: Microsoft says TRIM was "designed to trim the 7-bit ASCII space character (value 32)" and "does not remove
this nonbreaking space character". Google: its Trim whitespace option notes that a non-breaking space "will not be
trimmed". JavaScript removes the byte order mark because the language's own definition of white space includes
U+FEFF; Python's does not. The regular expression \s gave the same results as the trim
function in each language.
The practical rule: no standard trim removes a zero width space, and only some remove a no-break space or a byte order mark. Remove them by code point, or with a tool that knows them.
Where they come from
- No-break spaces: web pages (
), text copied from PDFs and Word, and numbers formatted with a space as thousands separator (French and other locales use a narrow no-break space). - Zero width spaces: websites and apps insert them to allow line breaks inside long words, URLs and hashtags; they come along when you copy.
- Byte order marks: Unicode's FAQ says a BOM "consists of the character code U+FEFF at the beginning of a data
stream". Excel's "CSV UTF-8" files start with one. Inside text, Unicode says it should be treated as a zero width
no-break space, and that the word joiner
U+2060is "strongly preferred" for that role. - Soft hyphens: word processors and websites that hyphenate long words.
How to find them
- Paste the text into the hidden character detector: it lists every hidden character with its line, column and name, and removes them.
- In Excel,
=LEN(A2)shows a length larger than the characters you can see.=CODE(LEFT(A2))and=UNICODE(MID(A2, n, 1))reveal the code of a given character. - In a text editor that can show invisible characters, or by searching for the code point.
How to remove them
- Excel:
=TRIM(SUBSTITUTE(SUBSTITUTE(A2, CHAR(160), " "), UNICHAR(8203), ""))turns no-break spaces into normal spaces, deletes zero width spaces (8203 isU+200B) and trims. - JavaScript:
s.replace(/[\u200B-\u200D\u2060\uFEFF\u00AD]/g, '').replace(/[\u00A0\u202F\u2007]/g, ' ').trim() - Python:
re.sub(r'[\u200b-\u200d\u2060\ufeff\u00ad]', '', s).replace('\xa0', ' ').strip() - Without code: remove formatting cleans pasted text, and Compare two lists ignores these characters when it matches items, then tells you how many items had them.
When not to remove them
Zero width joiners build emoji (a family emoji is several emoji joined with U+200D) and are needed in
some scripts such as Persian and Hindi. No-break spaces keep a number and its unit together on one line. Remove them
from data you compare or import; leave them in text people will read.
Tools for this
- Compare two listsOnly in A, only in B, in both. Excel columns, near matches, CSV.
- Hidden character detectorFind and remove invisible characters: zero-width spaces, no-break spaces, tags.
- Remove formattingRemove formatting from text copied from Word, web pages, PDFs or emails.
- Remove spacesRemove extra spaces from text online: double spaces, spaces at the start and end of lines, tabs, no-break spaces, or every space.
Sources
- Unicode Character Database: UnicodeData.txt (names, categories)
- Unicode Character Database: PropList.txt (White_Space)
- Unicode Character Database: DerivedCoreProperties.txt (Default_Ignorable_Code_Point)
- Unicode FAQ: UTF-8, UTF-16, UTF-32 and BOM
- Microsoft Support: TRIM function
- Google Docs Editors Help: Remove duplicates and trim whitespace