0

I want to replace unicode characters with space. For example, I have this string

This was a very successful meeting.\u000b\u000bWe agreed on several topics:\u000b New strategy\u000b Development ressources\u000b Project optimization

and I want to replace \u000b with space. Currently, I am doing it this way i.e.

var str = "This was a very successful meeting.\u000b\u000bWe agreed on several topics:\u000b";
var replaceStr = str.replace(/[\u000b\u00A0\u1680​\u180e\u2000-\u2009\u200a​\u200b​\u202f\u205f​\u3000\u000b-]/g, ' ');

but it's not replacing these unicode characters with space.

Thank you

2
  • If I try it out in Browser-Console it works. Are you sure you continue working with replaceStr instead of str? Commented Jun 11, 2020 at 9:29
  • yes. I am doing console 'replaceStr'. Commented Jun 11, 2020 at 9:57

1 Answer 1

1

If you are seeing unescaped Unicode code point that probably means that backslash character is escaped in the source. In this case, you can replace the code point with a character it represents:

function unescapeUnicode(raw) {
  return raw.replace(
    /\\u([0-9a-f]{4})/gi,
    (_, c) => String.fromCharCode(Number.parseInt(c, 16))
  )
}

const input = 'This was a very successful meeting.\\u000b\\u000bWe agreed on several topics:\\u000b New strategy\\u000b Development ressources\\u000b Project optimization'

document.body.textContent = unescapeUnicode(input)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.