Skip to content

zero-width space

homepage-banner

Zero-width space is a Unicode character that has no visible width, but is used to separate characters or words. It is often used in programming and web development to avoid line breaks or for formatting purposes. However, it can also be used for malicious intent, such as hiding text or injecting code.

Sometimes, when you copy and paste commands or code from web pages, you may encounter issues when trying to execute them. To ensure that your code runs smoothly, it’s important to check for any “zero-width space” characters that may be hiding within the text.

Demo text

text ​with ​zero ​width ​space

Copy and pase into vim and Sublime Text, you will see

text <0x200b>with <0x200b>zero <0x200b>width <0x200b>space
## or
text <200b>with <200b>zero <200b>width <200b>space

How to find out

grep --perl-regexp '\x{200B}' text_file
## or
grep $'\u200b' text_file
## or
grep "$(printf %b '\u200b')" text_file

Reference

  • https://en.wikipedia.org/wiki/Zero-width_space
  • https://unicode-table.com/en/200B
  • https://superuser.com/questions/808716/linux-shell-command-to-grep-unicode-character-zero-width-space-u200b
Leave a message