Regex Unicode

Match emoji, CJK, and scripts correctly with unicode mode.

  • unicode regex
  • match emoji
  • CJK regex
  • unicode property
  • astral char

Regex Unicode

Match emoji, CJK, and scripts correctly with unicode mode.

Commands

CommandWhat it does
/\p{L}/uAny letter, any script
/\p{Script=Han}/uHan characters
/\p{Emoji}/uEmoji codepoints
/\u{1F600}/uOne astral char by codepoint
/^[\p{L}\p{N}_.-]+$/uUnicode-safe username

Example

/\p{Script=Han}+/gu.test('cheatsheet')

FAQ

Why does an emoji have length 2?

Astral chars are UTF-16 surrogate pairs; spread into an array for real counts.

When is backslash-w wrong?

It is ASCII-only; use unicode letter and number properties for international identifiers.

Частые вопросы

Why does an emoji have length 2?
Astral chars are UTF-16 surrogate pairs; spread into an array for real counts.
When is backslash-w wrong?
It is ASCII-only; use unicode letter and number properties for international identifiers.

Regex