Remove accents/diacritics in a string in JavaScript

前端 未结 29 2561
轻奢々
轻奢々 2020-11-21 13:29

How do I remove accentuated characters from a string? Especially in IE6, I had something like this:

accentsTidy = function(s){
    var r=s.toLowerCase();
           


        
29条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-21 13:57

    All the above isn't working with decomposed character as used on Mac OS. In order to remove diacritics in that case it is more simple :

    r = r.replace(new RegExp(/[\u0300-\u036f]/g),"")
    

    see comment from Olivier Miakinen on : https://groups.google.com/d/msg/fr.comp.lang.regexp/6IGJTbedGTM/G0sB2kAsR34J (posted in french)

提交回复
热议问题