Javascript - Efficiently replace all accented characters in a string
const strip_accents = (str) => str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
Two things are happening here:
normalize()ing toNFDUnicode normal form decomposes combined graphemes into the combination of simple ones. TheèofCrèmeends up expressed ase +̀.- Using a regex character class to match the
U+0300 → U+036Frange, it is now trivial to globally get rid of the diacritics, which the Unicode standard conveniently groups as the Combining Diacritical Marks Unicode block.
Same with another syntax:
str.normalize('NFKD').replace(/\p{Diacritic}/gu, '');