Anthony Fu @

Match Chinese Characters

Feb 25, 2021 · 2min

When you need to detect if a string contains Chinese characters, you would commonly think about doing it will RegExp, or grab a ready-to-use package on npm.

If you Google it, you are likely end up with this solution:


It works, but a bit dirty. Fortunately, I found a much simpler solution today:

!!'你好'.match(/\p{Script=Han}/u) // true

It’s called Unicode property escapes and already available in Chrome 64, Firefox 79, Safari 11.1 and Node.js 10.

All available scripts here.

> comment on mastodon / twitter
CC BY-NC-SA 4.0 2021-PRESENT © Anthony Fu