Efficiently replace all accented characters in a string?

后端 未结 21 2835
别跟我提以往
别跟我提以往 2020-11-22 04:35

For a poor man\'s implementation of near-collation-correct sorting on the client side I need a JavaScript function that does efficient single character rep

21条回答
  •  花落未央
    2020-11-22 05:23

    I can't think about an easier way to efficiently remove all diacritics from a string than using this amazing solution.

    See it in action:

    var string = "öäüÖÄÜ";
    
    var string_norm = string.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
    console.log(string_norm);

提交回复
热议问题