Android - How to filter emoji (emoticons) from a string?

前端 未结 4 1339
天命终不由人
天命终不由人 2020-12-09 00:22

I\'m working on an Android app, and I do not want people to use emoji in the input.

How can I remove emoji characters from a string?

4条回答
  •  孤街浪徒
    2020-12-09 00:39

    Emojis can be found in the following ranges (source) :

    • U+2190 to U+21FF
    • U+2600 to U+26FF
    • U+2700 to U+27BF
    • U+3000 to U+303F
    • U+1F300 to U+1F64F
    • U+1F680 to U+1F6FF

    You can use this line in your script to filter them all at once:

    text.replace("/[\u2190-\u21FF]|[\u2600-\u26FF]|[\u2700-\u27BF]|[\u3000-\u303F]|[\u1F300-\u1F64F]|[\u1F680-\u1F6FF]/g", "");

提交回复
热议问题