Regex emoji help

Post your questions and help other users.

Moderator: Martin

Post Reply
Wibbly
Posts: 358
Joined: 17 Mar 2014 09:02

Regex emoji help

Post by Wibbly » 18 Mar 2020 19:14

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?

Wibbly
Posts: 358
Joined: 17 Mar 2014 09:02

Re: Regex emoji help

Post by Wibbly » 19 Mar 2020 13:25

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?

User avatar
Desmanto
Posts: 2599
Joined: 21 Jul 2017 17:50

Re: Regex emoji help

Post by Desmanto » 19 Mar 2020 18:31

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.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Wibbly
Posts: 358
Joined: 17 Mar 2014 09:02

Re: Regex emoji help

Post by Wibbly » 19 Mar 2020 18:51

Thanks. For the record, what would the regex syntax be?

User avatar
Desmanto
Posts: 2599
Joined: 21 Jul 2017 17:50

Re: Regex emoji help

Post by Desmanto » 21 Mar 2020 15:47

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.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply