← Blog · · ConvertCaseHQ Team · 7 min read

How to Standardize Data: Text Case Normalization Techniques

To standardize text data, run every value through the same steps in the same order: normalize Unicode, remove invisible characters, trim and collapse whitespace, fold the case, and only then compare or deduplicate. Keep the original value for display and store the result as a separate match key. Skip a step, or run the steps in a different order in two places, and values that look identical stop matching.

Below, each step gets its own section with the traps that make it necessary, followed by the full pipeline in Python, JavaScript and SQL.

Keep the original, compare on a match key

Normalization throws information away. That's the point, but it means you shouldn't overwrite what people typed. Store name as entered and add a name_key column (or a computed index) that holds the normalized form. Searches, joins and duplicate checks use the key; screens and emails use the original.

Email addresses show why. RFC 5321, the SMTP standard, says the part before the @ "MUST BE treated as case sensitive", while domains are not. The same section adds that exploiting this "impedes interoperability and is discouraged", so matching addresses case-insensitively is the practical choice. Storing Ada@Example.com exactly as typed and matching on lower(email) gives you both: the address is preserved, and nobody can register twice by changing a capital.

Step 1: Unicode normalization (NFC or NFKC)

The word "café" can be stored two ways: with é as a single code point, or as a plain e followed by a combining accent. They look identical, and a naive comparison says they're different strings. Unicode normalization fixes that by converting text to one standard form, defined in Unicode Standard Annex #15:

  • NFC composes characters where possible, so both versions of "café" become the same four-character string. It changes nothing a reader would notice, which makes it the right form for text you store and display.
  • NFKC does that and also folds "compatibility" characters into their plain equivalents: the ligature fi becomes fi, full-width Full becomes Full, ① becomes 1, ™ becomes TM, and a no-break space becomes an ordinary space.

NFKC is the better choice for match keys, usernames and search, because it catches lookalikes pasted from PDFs and phone keyboards. Don't use it on stored text, though: it turns x² into x2, which changes the meaning.

Step 2: Whitespace, including the characters you can't see

Trimming the ends and collapsing runs of spaces is the easy part. The hard part is that "whitespace" means different things to different tools:

  • No-break spaces (U+00A0) often arrive with text copied from web pages, Word and spreadsheets. Python's \s and JavaScript's \s both match them, but PostgreSQL's btrim() removes only ordinary spaces unless you list other characters. NFKC turns them into ordinary spaces, which is one reason it goes first.
  • The byte order mark (U+FEFF) ends up at the start of a CSV's first cell when a file saved with one is read as plain text. JavaScript's \s and trim() remove it; Python's \s and str.split() don't.
  • The zero-width space (U+200B) isn't whitespace to Python or JavaScript, so delete it explicitly. Be careful with its relatives U+200C and U+200D: they're invisible too, but Persian text and emoji sequences depend on them.

Step 3: Case folding, and why lower() isn't always enough

For comparisons, convert everything to one case. In Python, prefer str.casefold() over lower(): it's designed for caseless matching, so "Straße".casefold() and "STRASSE".casefold() are both "strasse", while lower() leaves the ß alone. JavaScript has no casefold; toLowerCase() works for most keys, and for comparing strings in an interface, Intl.Collator with sensitivity: "accent" ignores case but not accents.

Databases can do the folding for you through collations, and they don't agree on defaults:

  • MySQL 8.0 uses utf8mb4_0900_ai_ci by default: accent-insensitive and case-insensitive, so 'café' = 'CAFE' is true. It's also a NO PAD collation, so trailing spaces count, unlike older collations such as utf8mb4_general_ci.
  • PostgreSQL compares case-sensitively unless you compare on lower() or define a nondeterministic ICU collation.
  • SQLite's built-in lower() and NOCASE only handle ASCII: lower('ÉCOLE') returns École.

The Turkish dotted İ

Turkish has two letter i's: dotted i/İ and dotless ı/I. Default Unicode casing doesn't know that, so in both Python and JavaScript, lowercasing "İstanbul" gives i plus a combining dot above: nine characters instead of eight. With Turkish rules, JavaScript's "İstanbul".toLocaleLowerCase("tr") gives istanbul and "istanbul".toLocaleUpperCase("tr") gives İSTANBUL. Python's string methods ignore locale entirely.

The opposite problem bites in Java, whose toLowerCase() uses the machine's default locale. Its own documentation warns that "TITLE".toLowerCase() returns tıtle under a Turkish locale and recommends toLowerCase(Locale.ROOT). PostgreSQL's lower() also follows the collation: in our tests, COLLATE "tr-x-icu" gave istanbul and the root ICU collation gave the dotted version.

Our rule: match keys use locale-independent folding, so the same input gives the same key on every server. Text shown to people uses the rules of its language. ConvertCaseHQ's own case converter works this way: Turkish casing on the Turkish version of the site, locale-free rules everywhere else, and always locale-free rules for identifier styles like snake_case.

Step 4: Deduplicate on the key, not the raw value

Once you have a key, duplicates are easy to find. Group by the key, look at the groups with more than one row, and decide which record survives. Automatic merging is fine for a mailing list. For customer records, list the collisions and let a person check them, because "Ada Lovelace" and "ada lovelace" are probably one person and two "John Smith"s probably aren't.

The pipeline in Python, JavaScript and SQL

Python, for single values and for a pandas column:

import re
import unicodedata

INVISIBLE = re.compile("[\u200b\ufeff]")   # zero-width space, byte order mark

def match_key(value: str) -> str:
    value = unicodedata.normalize("NFKC", value)
    value = INVISIBLE.sub("", value)
    value = " ".join(value.split())   # trim, and collapse all runs of whitespace
    return value.casefold()

# pandas
df["name_key"] = df["name"].map(match_key)
duplicates = df[df.duplicated("name_key", keep=False)]
df = df.drop_duplicates(subset="name_key", keep="first")

JavaScript:

const INVISIBLE = /[\u200B\uFEFF]/g; // zero-width space, byte order mark

function matchKey(value) {
  return value
    .normalize("NFKC")
    .replace(INVISIBLE, "")
    .replace(/\s+/g, " ")
    .trim()
    .toLowerCase();
}

// Keep the first row for each key
const seen = new Map();
for (const row of rows) {
  const key = matchKey(row.name);
  if (!seen.has(key)) seen.set(key, row);
}
const unique = [...seen.values()];

PostgreSQL 13 or later (for normalize()):

-- Find duplicate names
SELECT lower(regexp_replace(btrim(normalize(name, NFKC)), '\s+', ' ', 'g')) AS name_key,
       count(*)
FROM customers
GROUP BY 1
HAVING count(*) > 1;

-- Stop duplicate emails at the door
CREATE UNIQUE INDEX customers_email_key ON customers (lower(email));

With that index in place, inserting ada@example.COM after Ada@Example.com fails with a duplicate key error, which is exactly what you want.

Consistent formats beyond case

The same idea applies to every field with more than one way of writing the same thing. Pick one canonical form and convert on the way in: dates as ISO 8601 (2026-06-11), phone numbers in international E.164 form (+14155550123), countries as ISO 3166 codes (DE, not "Germany", "germany" and "Deutschland"), and booleans as one pair of values rather than yes/Y/true/1.

Quick one-off cleanups

For a pasted list rather than a database, our case converter has the basic steps as buttons: Clean whitespace (collapses runs of spaces and drops empty lines), lowercase, and Dedupe lines. Run them in that order, because Dedupe lines compares lines exactly as they are. It doesn't do Unicode normalization, so for data with accents from mixed sources, the code above is the safer route. Our diff tool is handy for checking what a cleanup changed, and our guide to cleaning up messy pasted text covers the stray characters Word and PDFs leave behind.

The order to remember: keep the raw value, normalize Unicode, strip invisible characters, fix whitespace, fold case, then deduplicate on the key. Do it the same way everywhere, ideally in one shared function, and most matching bugs never happen.

© 2026 ConvertCaseHQ. All rights reserved.