'zero width space'에 해당되는 글 1건

  1. 2022.11.23 Remove zero-width space characters from a JavaScript string
카테고리 없음2022. 11. 23. 18:18

가끔씩 값을 직접 타이핑하지 않고 엑셀이나 다른 프로그램에서 복사, 붙여넣기를 통해서 입력하면 %E2%80%8B가 붙으면서 API조회가 정상적으로 되지 않는 현상이 있다.

이럴 때는 zero width space 문서를 치환시켜주면 해결된다.

Unicode has the following zero-width characters:

U+200B zero width space
U+200C zero width non-joiner Unicode code point
U+200D zero width joiner Unicode code point
U+FEFF zero width no-break space Unicode code point
To remove them from a string in JavaScript, you can use a simple regular expression:

var userInput = 'a\u200Bb\u200Cc\u200Dd\uFEFFe';
console.log(userInput.length); // 9
var result = userInput.replace(/[\u200B-\u200D\uFEFF]/g, '');
console.log(result.length); // 5
Posted by 미랭군