replace emoji unicode symbol using regexp in javascript

前端 未结 9 995
醉酒成梦
醉酒成梦 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:02

    Below regex pattern worked for me in java.

    "[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]"
    

    As java String uses UTF-16 encoding and as emoji's are above 0xFFFF as well, this regex pattern consider surrogate pairs to identify emojis.

提交回复
热议问题