Sign in Start free

16Unicode, emoji and Thai text

With the u flag, \p{…} matches by Unicode property: letters, scripts, emoji.

\w only knows ASCII letters, so it does not match é, ก or 中. With the u flag JavaScript understands Unicode properties:

\p{L}any letter of any language
\p{Lu}an uppercase letter
\p{N}any number, incl. Thai digits ๑๒๓
\p{Script=Thai}a Thai character
\p{Extended_Pictographic}emoji

The u flag also treats emoji (which use two UTF-16 code units) as one character. In Java, use \p{IsThai} and the U flag for Unicode-aware \w.

Exercises