How to remove Unicode characters from Javascript (string.replace())

Asked 2 years ago, Updated 2 years ago, 88 views

Hi, I'm trying to delete two unicodes in the text with javascript: &zwj and &emsp, but it doesn't work as I thought.

<div class="item" data-value="0399">&zwj;&emsp;Fruits </div>
<div class="item" data-value="0359">&zwj;&emsp;&zwj;&emsp;Banana And Apple </div>
<div class="item" data-value="0359">&zwj;&emsp;&zwj;&emsp;Apple And Kiwi </div>
<div class="item" data-value="0359">&zwj;&emsp;&zwj;&emsp;Kiwi And pineapple </div>

It's currently in this structure.

When there is only &emsp, just take the text content or text of all nodes.

text.replace(/&emsp/g, ''); This eliminates all blank characters.

If &zwj; and &emsp; are present together,

text.replace(/&zwj;&emsp;/g, ''))
text.replace(/&zwj;|&emsp;/g, ''))
text.replace(/&emsp;/g, ''))

There is no change in doing all three below.

How can I erase those &zwj; and &emsp;?

according to one's search &emsp; is Unicodeu2003 &zwj; is Unicodeu200D Do I have to solve it using this?

Masters, please answer!

javascript regex

2022-09-22 19:27

1 Answers

When text is divided into &zwj;&emsp;Fruit like this,

Cut the string with text.split(';') and

I think it's the easiest way to get only the last element of an array.


2022-09-22 19:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.