Page 1 of 1

Regex emoji help

Posted: 18 Mar 2020 19:14
by Wibbly
Suppose I wanted to replace emoji in a string with it's texuarl equivalent. I think I need to search for Unicodes, so for example convert 😀, unicode 1F600, to :-) wherever it occurs in the string...

What should the regex expression look like?

Re: Regex emoji help

Posted: 19 Mar 2020 13:25
by Wibbly
Just realised the forum converst them back! I meant:

I think I need to search for Unicodes, so for example convert "😀", unicode 1F600, to ": - )" (without the spaces or quotes!) wherever it occurs in the string...

What should the regex expression look like?

Re: Regex emoji help

Posted: 19 Mar 2020 18:31
by Desmanto
If you only need simple replace, using replace() is enough. Emoji should be recognized properly, just like other UTF-8 chars.

Code: Select all

str = "hahahaha😀Funny ­😀";
rep = replace(str, "­😀", ":-)");
Using replaceAll() also work here, since it is only single (emoji) char.

Re: Regex emoji help

Posted: 19 Mar 2020 18:51
by Wibbly
Thanks. For the record, what would the regex syntax be?

Re: Regex emoji help

Posted: 21 Mar 2020 15:47
by Desmanto
Surprisingly, the emoji itself can be used as the syntax. That's why replaceAll() also work there (replaceAll() is the regex version of replace() ). Try it in the regex tester, no need to escape it or using the unicode.