Skip to main content
ajayp702
September 15, 2023
Solved

Regular Expression to remove emojis from text input

  • September 15, 2023
  • 3 replies
  • 0 views

We have freeform paragraph field, where user can enter any text string except the emojis. I have tried some of following regexreplaceall function which works fine to remove emojis but it also removes some of the special chars as well. Any suggestion on how to just eliminate emojis by completely removing it or just replace it with text string.

input: "afs saf [emoticon:4191f5ee34e248a29fa0dbe8d975f74a][emoticon:5ced9b85a4a246058e4772ef2b9956f4][emoticon:33306c418930400bac28808410f8ac8b][emoticon:ac85b29e2ff049dd9278224b337cdf43][emoticon:ccfc0979d5bf49dc92a54d454ae8fe68] sdfa sdf___~!@#$%^&*()_+{}|:<>?"

Function:  regexreplaceall("[^\u1F600-\u1F6FF\s]", ri!input, "" )

currentOutput: "afssafsdfasdf___~@^_{}|:<>?"

desireOutput"afs saf  sdfa sdf___~!@#$%^&*()_+{}|:<>?"

Thanks!

Ajay

    Best answer by ajayp702

    Thanks for your reply [mention:126a676c85024855948336691b0a7b92:e9ed411860ed4f2ba0265705b8793d05] !

    I got an easy solution using clean() function, that eliminates any chars which are not printable.

    3 replies

    stefanhelzle0001
    Brainy
    September 15, 2023

    For the regex replacing other characters as well, check this post: https://stackoverflow.com/questions/53383475/replace-all-emojis-from-a-given-unicode-string

    My first question: Why do you want to remove emojis? Database issues could be solved by switching to a UTF8MB4 collation.

    Solution: code() returns the integer number of characters. Then you can remove/replace the required ranges and turn it back into a string using char().

    ajayp702
    ajayp702AuthorAnswer
    September 15, 2023

    Thanks for your reply [mention:126a676c85024855948336691b0a7b92:e9ed411860ed4f2ba0265705b8793d05] !

    I got an easy solution using clean() function, that eliminates any chars which are not printable.

    stefanhelzle0001
    Brainy
    September 16, 2023

    Yeah ... if this is only about English, that should work. If you need to support multiple languages, you need to test that.