replace emoji unicode symbol using regexp in javascript

前端 未结 9 989
醉酒成梦
醉酒成梦 2020-12-15 10:42

As you all know emoji symbols are coded up to 3 or 4 bytes, so it may occupy 2 symbols in my string. For example \'

9条回答
  •  北海茫月
    2020-12-15 11:06

    maybe you can take a look of this article: http://crocodillon.com/blog/parsing-emoji-unicode-in-javascript

    the emoji unicode from \u1F601 to \u1F64F

    translate to javascript's utf-16 is \ud83d\ude00 to \ud83d\ude4f

    the first char is always \ud83d.

    so the reg is out:

    /\ud83d[\ude00-\ude4f]/g
    

    hope this can make some help

提交回复
热议问题