Proper Regex to find and replace escaped UTF-8 strings
Posted
by
Piet Binnenbocht
on Stack Overflow
See other posts from Stack Overflow
or by Piet Binnenbocht
Published on 2013-10-22T16:32:09Z
Indexed on
2013/10/22
21:54 UTC
Read the original article
Hit count: 222
(edited) I am reading a JSON file that includes some UTF-8 characters that are encoded like this: "\uf36b
". I am trying to write a RegExp to convert this to an HTML entity that looks like "🍫
". This displays the character correctly in my html page.
I haven't been able to correctly display the character that should be associated with "\uf36b", especially when in a longer sentence that also includes other text.
How can I write a regexp that replaces strings like "\uf4d6" and "\uf36b" but leaves other text alone?
Example:
var str = "I need \uf36b #chocolate";
This should be converted to:
I need 🍫 #chocolate;
© Stack Overflow or respective owner