去除ZERO WIDTH SPACE 零宽字符: 看不见却占位置的字符

ZERO WIDTH SPACE

由于历史原因,编码方案中保留着该类编码

解决方案

1. 替换
  ```js
    str.replace(/[\u200B-\u200D\uFEFF]/g, '');
  ```

2. 另一种替换
```js
    str.replace(/\u8203/g, '');
    str.replace(/\uB200/g'');
```

3. 还有一种替换
```js
    str.replace(/(^[\s\u200b]*|[\s\u200b]*$)/g, '')
```

4. 也可以先获取正常字符,然后join
   ```js
     var res = str.match(/\w/g);
     str = res.join('');
    ```
posted @ 2019-11-18 15:19  果感  阅读(5499)  评论(0编辑  收藏  举报