1

Basically what the title says, I'm looking for the best way to remove all emojis from a string.

2
  • 2
    You'll have to be more specific. Unicode and Emacs have differing definitions of what constitutes an emoji, and then there are eg emoji ZWJ sequences to worry about.
    – rpluim
    Commented Sep 28, 2023 at 13:24
  • @rpluim I'm scraping a web using url-retrieve-synchronously, getting the content using buffer-substring, formatting strings with emojis messes up functions that format strings (I guess that's where ZWJ comes to play, although I'm not familiar with that), is there a way to remove all unicode characters that display emojis and only emojis? I've tried something like (setf my-string (replace-regexp-in-string "[\x{1F600}-\x{1F64F}\x{2700}-\x{27BF}\x{1F680}-\x{1F6FF}\x{24C2}\x{1F1E0}-\x{1F1FF}]" "" my-string)) but it also removes other normal chatacters Commented Sep 29, 2023 at 1:20

1 Answer 1

0

For emoji which are single characters, and which Emacs displays as emojis, you can do something like:

(defun strip-emoji (str)
  "Remove characters which are part of the `emoji' script from STR."
  (cl-remove-if (lambda (c)
                  (equal (aref char-script-table c) 'emoji))
                str))

(strip-emoji "This: 😀 or that 😃") => "This:  or that "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.