I have a string called completionBar which contains this:
let completionBar = `〚⬛⬛⬛⬛⬛〛`;
I'm trying to replace a single ⬛ with ⬜, so I tried:
completionBar.replace(/\U+2B1B/, 'U+2B1C');
but nothing happen, what I did wrong?
You can use /⬛/g in .replace().
I would try as the following if you want to replace all:
let completionBar = `〚⬛⬛⬛⬛⬛〛`;
const result = completionBar.replace(/⬛/g, '⬜');
console.log(result)
If you need only the first to replace:
let completionBar = `〚⬛⬛⬛⬛⬛〛`;
const result = completionBar.replace('⬛', '⬜');
console.log(result)
I hope this helps!
lastIndexOf() then using the answer's solution from here: How do I replace a character at a particular index in JavaScript?.
completionBar.replace(/\u2B1B/, String.fromCharCode("0x2B1C"))