How to remove emoji code using javascript?

后端 未结 12 2195
忘了有多久
忘了有多久 2020-11-27 05:04

How do I remove emoji code using JavaScript? I thought I had taken care of it using the code below, but I still have characters like

12条回答
  •  隐瞒了意图╮
    2020-11-27 05:39

    For me none of the answers completely removed all emojis so I had to do some work myself and this is what i got :

    text.replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, '');
    

    Also, it should take into account that if one inserting the string later to the database, replacing with empty string could expose security issue. instead replace with the replacement character U+FFFD, see : http://www.unicode.org/reports/tr36/#Deletion_of_Noncharacters

提交回复
热议问题