Concrete Javascript Regex for Accented Characters (Diacritics)

后端 未结 9 1001
庸人自扰
庸人自扰 2020-11-22 17:22

I\'ve looked on Stack Overflow (replacing characters.. eh, how JavaScript doesn\'t follow the Unicode standard concerning RegExp, etc.) and haven\'t really found a concrete

9条回答
  •  隐瞒了意图╮
    2020-11-22 17:41

    You can remove the diacritics from alphabets by using:

    var str = "résumé"
    str.normalize('NFD').replace(/[\u0300-\u036f]/g, '') // returns resume
    

    It will remove all the diacritical marks, and then perform your regex on it

    Reference:

    https://thread.engineering/2018-08-29-searching-and-sorting-text-with-diacritical-marks-in-javascript/

提交回复
热议问题