I have a string that contains utf-8 encoded emojis. The string is escaped. I need to convert the utf-8 into emojis and print them properly. For example:
input: \\xe2\\x80\\x9c@VineFights: He does not care Lamo!!!
\\xf0\\x9f\\x98\\x82 https:\\/\\/t.co\\/TwmYFEhx9g\\xe2\\x80\\x9d\\xf0\\x9f\\x98\\x82\\xf0
\\x9f\\x98\\xad\\xf0\\x9f\\x98\\xad
Expected output: He does not care Lamo!!! URL”
This is one sinle string (without breaks). I have broken it down for fit in one view in this question.
My Idea is to extract emojis using regex (\\\\x[a-fA-F0-9]{2})+
and replace them by converting bytes manually into emojis. This failed in several cases like the one in example. It also feels like unnecessary hacky/ugly solution. What's the right way to handle it?
(More interested to know how this is actually done in real world. Any examples is appreciated)