Remove accents and diacritics from a string in JavaScript
Codemia Knowledge Hub ·
Decompose the string with normalize("NFD"), then delete the combining marks with a regular expression: str.normalize("NFD").replace(/[\u0300-\u036f]/g, ""). This is useful for building URL slugs, making search accent-insensitive, or keeping a dataset uniform.
Unicode normalization with normalize("NFD")
String normalization has been part of ECMAScript since ES2015:
normalize("NFD")splits each character into its base letter and its diacritical marks. NFD is Normalization Form Decomposition, soébecomeseplus a combining acute accent./[\u0300-\u036f]/gmatches the combining diacritical marks fromU+0300toU+036F, andreplaceremoves them.
Where normalization falls short
- Ligatures such as
œandæare not decomposed this way and need extra replacements. - Some characters have no straightforward decomposed form and are not handled.
A character map for ligatures and older environments
For environments without .normalize(), or for exceptions like ligatures and ß, map characters explicitly:
replace() with a callback looks up each matched character in the map and returns its replacement. You must list every character you want to handle.
| Method | Description | Limitations |
String Normalization (normalize) | Uses Unicode standard to decompose characters and remove diacritics | High dependency on client environment Unicode compatibility |
| Mapping | Maps each specific character to its non-diacritic counterpart | Requires manual definition of all mappings, less dynamic |
Normalization handles most cases and is supported in modern environments. Add a map on top when you need ligatures or must support environments without normalize().
Related reading
- Remove all non-numeric characters from a string in swift
- Remove all special characters, punctuation and spaces from string
- Remove ALL white spaces from text
- Remove all whitespace in a string
- Remove all child elements of a DOM node in JavaScript
- Remove an onclick listener
- Remove characters after specific character in string, then remove substring?
- Remove final character from string
System design interview problems on this topic
- Design Google Doc: solution and walkthrough
- Design Facebook Messenger: solution and walkthrough
- Design Typeahead Suggestion: solution and walkthrough
- Design an Online Presence Indicator Service: solution and walkthrough
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.