re: Quick and easy way of counting UTF-8 characters in Javascript VIEW POST


Hi Alexandru,

Nice post, I recently had to deal with this.
There are some cases where destructuring wont work, for example with punctuation.

▶ 9

My original code is in clojurescript:

In javascript:
"וְאֵ֗לֶּה".split(/(\P{Mark}\p{Mark}*)/u).filter((val) => val)
▶ ["וְ", "אֵ֗", "לֶּ", "ה"]


Hi Gal,

That's really interesting, any idea why that might be the case ?


I think is because punctuation symbols are separate unicode characters that are collapsed into the first preceding non-Mark character.

Example: ד ָ דָ

So if you want to count the visible characters, you need to account for the marks.

code of conduct - report abuse