Emoji string extraction

Hi All,

I'm trying to emoji unicodes from text. For example
""Sepedanya biasa, spiritnya mantap jiwaaa" <U+0001F601><U+0001F6B4><U+0001F6B4> Bertumbuhlah, lebih sehat, lebih kuat, entah jasmani, rohani, atau relasi-relasi (persahabatan, kekerabatan, pernikahan, pekerjaan). Mulailah dari yg ada, jgn tunggu lengkap sarananya atau tepat situasinya. Mulai dan tekuni saja salah satunya, yg lain akan mengikut pd waktunya. Jangan menyerah kalau jatuh atau kambuh. Itu proses bertumbuh yg harus dikayuh, rute merupa Kristus yg layak ditempuh.

I want to extract all the U+ codes in this string and as well apply to a dataframe. Thank you

Hi,

Here is an example:

library(stringr)

text = "Sepedanya biasa, spiritnya mantap jiwaaa <U+0001F601><U+0001F6B4><U+0001F6B4> 
Bertumbuhlah, lebih sehat, lebih kuat, entah jasmani, rohani, atau relasi-relasi 
(persahabatan, kekerabatan, pernikahan, pekerjaan). Mulailah dari yg ada, jgn tunggu 
lengkap sarananya atau tepat situasinya. Mulai dan tekuni saja salah satunya, 
yg lain akan mengikut pd waktunya. Jangan menyerah kalau jatuh atau kambuh. 
Itu proses bertumbuh yg harus dikayuh, rute merupa Kristus yg layak ditempuh"

unicodes = str_match_all(text, "<(U+[^\\>]+)>")
location = str_locate_all(text, "<(U+[^\\>]+)>")

unicodes = cbind(data.frame(unicode = unicodes[[1]][,2]), location[[1]])

unicodes
#>      unicode start end
#> 1 U+0001F601    42  53
#> 2 U+0001F6B4    54  65
#> 3 U+0001F6B4    66  77

Created on 2020-09-14 by the reprex package (v0.3.0)

I used the str_match_all() function to extract all the unicodes based on the pattern of <U+ ... > then used the str_locate_all() with the same pattern to get the start and end location of each (should you like to know that too).

Hope this helps,
PJ

Ahah. Thank you peter!

Worked like magic

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.