Unicode Normalization and Text Search: Why Accents Don't Match
Your search for "café" finds nothing, and the word is plainly on the screen. The cause is usually that the two strings are different sequences of code points that happen to look the same. Normalize both the query and the text to one Unicode form, and they match.
Two ways to store é
Unicode allows the same visible letter to be stored in more than one way. MDN uses ñ as its example: it can be the single code point U+00F1, or the letter "n" (U+006E) followed by a combining tilde (U+0303). Since the code points differ, string comparison does not treat them as equal, and the two versions even have different lengths.
You can see it in a few lines of JavaScript:
const a = "ñ"; // ñ as one code point
const b = "ñ"; // n + combining tilde
a === b; // false
a.length; // 1
b.length; // 2Canonical equivalence
Unicode's name for this is canonical equivalence. UAX #15 defines it as an equivalence between characters or sequences that represent the same abstract character and should always have the same visual appearance and behavior. One of its listed kinds is the combining sequence: Ç is equivalent to C followed by a combining cedilla.
NFC and NFD in plain terms
Normalization is the process of picking one of the equivalent encodings and using it everywhere. The four forms are defined in the same report:
- NFD is canonical decomposition: letters are split into a base plus combining marks.
- NFC is canonical decomposition followed by canonical composition: letters are joined into single code points where possible.
- NFKD and NFKC do the same with compatibility decomposition, which folds more differences. More on those below.
Why a plain search misses it
A basic text search compares code points. If your note holds the decomposed "café" (c, a, f, e, combining acute) and you type the composed "café" (c, a, f, é), the sequences differ at the end, so there is no match. Neither string is broken. Both are valid, and both read as "café" to a person.
Normalization fixes this because it puts combining marks in a specified order and applies fixed rules to turn each string into one form. A binary comparison of the transformed strings then determines equivalence.
Normalize both sides before you compare
The rule is short: normalize the query and the text with the same form, then compare. In JavaScript:
const norm = (s) => s.normalize("NFC");
norm(note).includes(norm(query));normalize() uses NFC when you pass no argument, and it throws a RangeError for a form name it doesn't know. Which form you pick matters less than using the same one on both sides. For general text, the Unicode FAQ calls NFC the best form because it is more compatible with strings converted from legacy encodings, and says user-level comparison should behave as if it normalizes input to NFC.
The same FAQ gives two cautions. Concatenation can break normalization, so if you join two normalized strings, normalize the result. And length can change: normalized text is usually the same length or shorter, but it can expand. If you map a match back to a position in the original, don't assume the offsets line up.
If your search uses a pattern, the same rule applies: normalize the text and the pattern first, and keep in mind that regex flavors differ from one editor to the next.
Plain ASCII is unaffected. UAX #15 notes that text containing only ASCII characters is left unchanged by every normalization form, which is why this bug only appears once accents, and other scripts that use combining marks, enter the picture.
Where decomposed text comes from
Most text you type arrives composed, so decomposed text tends to come from somewhere specific. File names are the best-known source on Apple platforms. The Unicode FAQ notes that Apple's old HFS+ file system stores file names in a variant of NFD, that the newer APFS doesn't enforce that, and that the macOS Finder still decomposes file names. A name copied from the Finder into a note can therefore carry decomposed letters while the rest of your note is composed. We covered that case in detail in why accented file names break between Mac and everything else, and it also affects glob patterns that try to match such a name.
When NFKC loose matching helps
NFC and NFD keep the distinction between characters that only look alike. NFKC and NFKD go further. The Unicode FAQ says that for loose matching, programs may want these forms, which remove compatibility distinctions. MDN gives a search example: "ff".normalize("NFKD") turns the "ff" ligature into "ff", which is appropriate for search because a user can then find it by typing "f", though not for display.
The trade-off is real. The FAQ warns that these forms lose information and suit a restricted domain such as identifiers, and UAX #15 says they must not be blindly applied to arbitrary text. A reasonable approach is to keep your stored text as it is, and apply the looser form only to a search index or a comparison key.
How Carets fits in
Carets is a native notes and code editor for iPhone, iPad, and Mac, built around plain text. That matters here because your notes stay plain text files, so the characters in them are exactly the code points you or a pasted source put there. When a search or a script misses an accented word, you can open the file, check the characters, and fix them, instead of working inside a format you can't inspect.
Carets handles Markdown, plain text, and code with syntax highlighting in one editor, so the JavaScript snippet above, the note it applies to, and the config file next to it can sit together, organized into files, projects, and tags. If you keep notes and code in plain text on Apple devices, get Carets on the App Store for iPhone, iPad, and Mac.
Frequently Asked Questions
Why does searching for café not find café?
The two strings look identical but may use different code points: one stores é as a single character, the other as e plus a combining accent. A plain comparison sees different sequences and reports no match. Normalizing both sides to the same form fixes it.
Should I use NFC or NFD for search?
Unicode recommends that user-level comparison behave as if it normalizes input to NFC, and calls NFC the best form for general text. What matters most is that the query and the text use the same form.
Is NFKC safe for every search?
No. NFKC and NFKD fold compatibility differences such as ligatures and fullwidth forms, which helps loose matching but loses information. Use them deliberately, on a search key or index, not on all stored text.
Does normalization change the length of a string?
Yes. The composed and decomposed forms of the same text have different lengths, so a character count or a cursor offset can change after normalizing.