1

Ok please help - I am having trouble unescaping all the unicode/utf-8 in my javascript string. I looked at this question but I don't understand how to form a regex that covers everything I need. For example, a string I have might be: "\xe2\x80\x98my\u002c union" and I would want an output of 'my, union. I am very very confused about how to deal with this format, I tried looking at this resource but I just don't understand how to use or construct a regex. Also, if there is another much easier way to unescape these characters, ideas would be welcome, I am a total beginner at this. I did try unescape(JSON.parse(mystring)) but this did not work either. Please help!!

Community
  • 1
  • 1
mbaed
  • 11
  • 2

1 Answers1

2

You can use decodeURIComponent with escape, as detailed in this blogpost

decodeURIComponent(escape('\xe2\x80\x98my\u002c union')) // "‘my, union"
sfletche
  • 47,248
  • 30
  • 103
  • 119
  • I forgot to mention I already tried this option as well after reading that blogpost. I'm not sure why it didn't escape the characters – mbaed Aug 15 '15 at 12:04