How do I remove emoji from string

前端 未结 10 2199
你的背包
你的背包 2020-11-28 10:44

My problem is to remove emoji from a string, but not CJK (Chinese, Japanese, Korean) characters from a string using regex. I tried to use this regex:

REGEX =         


        
10条回答
  •  Happy的楠姐
    2020-11-28 11:21

    I am using one based on this script.

     def strip_emoji(text)
        text = text.force_encoding('utf-8').encode
        clean = ""
    
        # symbols & pics
        regex = /[\u{1f300}-\u{1f5ff}]/
        clean = text.gsub regex, ""
    
        # enclosed chars 
        regex = /[\u{2500}-\u{2BEF}]/ # I changed this to exclude chinese char
        clean = clean.gsub regex, ""
    
        # emoticons
        regex = /[\u{1f600}-\u{1f64f}]/
        clean = clean.gsub regex, ""
    
        #dingbats
        regex = /[\u{2702}-\u{27b0}]/
        clean = clean.gsub regex, ""
      end
    

    Results:

    irb> strip_emoji("

提交回复
热议问题