惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Spread Privacy
Spread Privacy
Project Zero
Project Zero
Cyberwarzone
Cyberwarzone
P
Privacy International News Feed
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
S
Schneier on Security
T
The Blog of Author Tim Ferriss
AI
AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
GRAHAM CLULEY
IT之家
IT之家
AWS News Blog
AWS News Blog
月光博客
月光博客
V
Vulnerabilities – Threatpost
The Hacker News
The Hacker News
T
Troy Hunt's Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Latest news
Latest news
美团技术团队
博客园_首页
S
SegmentFault 最新的问题
博客园 - Franky
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Security @ Cisco Blogs
Stack Overflow Blog
Stack Overflow Blog
Engineering at Meta
Engineering at Meta
云风的 BLOG
云风的 BLOG
L
LINUX DO - 热门话题
人人都是产品经理
人人都是产品经理
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
Vercel News
Vercel News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Simon Willison's Weblog
Simon Willison's Weblog
MyScale Blog
MyScale Blog
S
Securelist
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
雷峰网
雷峰网
The GitHub Blog
The GitHub Blog
博客园 - 聂微东
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org

Anthony Fu

Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony's Roads to Open Source - The Set Theory (React ver.) Mental Health in Open Source The Evolution of Shiki v1.0 The Magic in Shiki Magic Move Anthony's Roads to Open Source - The Progressive Path Anthony Fu Anthony Fu Anthony Fu Anthony's Roads to Open Source - The Set Theory Now, and the Future of Nuxt Devtools Anthony's Roads to Open Source - The Set Theory Anthony Fu Anthony Fu Stable Diffusion QR Code 101 Refining AI Generated QR Code Stylistic QR Code with Stable Diffusion Anthony Fu How I Manage GitHub Notifications Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Dev SSR on Nuxt with Vite Why I don't use Prettier Anthony Fu Anthony Fu Ship ESM & CJS in one Package Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Anthony Fu Reflection of Speaking in Public Anthony Fu Windi CSS and Tailwind JIT Typed Provide and Inject in Vue Color Scheme for VS Code Anthony Fu Anthony Fu Anthony Fu Anthony Fu Destructuring... with object or array? Anthony Fu Anthony Fu Make Libraries Working with Vue 2 and 3 Anthony Fu Anthony Fu Anthony Fu Anthony Fu
Anthony Fu
Anthony Fu · 2021-02-26 · via Anthony Fu

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:

/[\u4E00-\u9FCC\u3400-\u4DB5\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|[\uD86A-\uD86C][\uDC00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D]/

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

/\p{Script=Han}/u
!!'你好'.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.