Home / Guides

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

CharacterCodeUnicode categoryCounts as white space?
No-break spaceU+00A0Space separator (Zs)Yes
Narrow no-break spaceU+202FSpace separator (Zs)Yes
Figure spaceU+2007Space separator (Zs)Yes
Ideographic spaceU+3000Space separator (Zs)Yes
Zero width spaceU+200BFormat (Cf)No
Zero width non-joiner / joinerU+200C / U+200DFormat (Cf)No
Word joinerU+2060Format (Cf)No
Zero width no-break space (byte order mark)U+FEFFFormat (Cf)No
Soft hyphenU+00ADFormat (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).

CharacterJavaScript trim()Python strip()Excel TRIMGoogle Sheets Trim whitespace
Normal space U+0020RemovedRemovedRemovedRemoved
No-break space U+00A0RemovedRemovedKeptKept
Narrow no-break, figure, ideographic spaceRemovedRemovedKeptNot documented
Byte order mark U+FEFFRemovedKeptKeptNot documented
Zero width space U+200BKeptKeptKeptNot documented
Zero width joiners, word joiner, soft hyphenKeptKeptKeptNot 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+2060 is "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 is U+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

Sources