ZERO WIDTH SPACE zero-width characters: invisible character accounted location

ZERO WIDTH SPACE

Due to historical reasons, the coding scheme retains the class coding

solution

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('');
    ```

Guess you like

Origin www.cnblogs.com/nelson-hu/p/11882305.html