Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zero-width space vs zero-width non-joiner

What is the difference between zero-width space (U+200B) and zero-width non-joiner (U+200C) from practical point of view?

I have already read Wikipedia articles, but I can't understand if these characters are interchangeable or not.

I think they are completely interchangeable, but then I can't understand why we have two in Unicode set instead of one.

like image 792
john c. j. Avatar asked Jul 20 '26 18:07

john c. j.


1 Answers

A zero width non joiner (ZWNJ) only interrupts ligatures. These are hard to notice in the latin alphabet but are most frequent in serif fonts displaying some specific combinations of lowercase letters, such as "fi" below. There are a few widely used writing systems, such as the arabic abjad, that use ligatures very prominently.

Example of ligature fi

A zero width space (ZWSP) does interrupt ligatures, but it also creates opportunities for line breaks. Very good for displaying file paths and long URLs, but beware that it sometimes screws up copy pasting.

By the way, I tested regular expression matching in Python 3.8 and Javascript 1.5 and none of them match \s. Unicode considers these characters as formatting characters (similar to direction markers and such) as opposed to space or punctuation. There are other codepoints in the same Unicode block (e.g. Thin Space, U+2009) that are considered space by Unicode and do match \s.

like image 112
Ekevoo Avatar answered Jul 23 '26 12:07

Ekevoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!