Unicode mode — u, v, and what . matches in an emoji¶
Level: 301 · for anyone matching text that is not plain ASCII
Stub — an outline, not a lesson. There is no runnable example behind this page yet, so nothing on it has been through the check that backs every other claim in this library. The questions below are what the finished page has to answer.
One line: Without u, . matches one UTF-16 code unit, so /^.$/.test("😀") is false and /^..$/ is true; u makes . a code point, yet 👨👩👧 still takes five dots, and v adds \p{RGI_Emoji}, which matches it as one.
Keywords: unicodeSets, \p{…}, \p{RGI_Emoji}
What the finished page will answer¶
- What do
/^.$/,/^..$/and/^.$/usay about"😀", and why? - How many
.does👨👩👧take underu, and what matches it as one unit underv? - What does
\p{L}mean withoutu, and what does it match withu? - What do the
vflag's set operations do, such as[\p{L}--[a-z]]and&&? - Which escapes that pass without
ubecome aSyntaxErrorwith it, such as\a? - How does
itreat the Kelvin sign (U+212A) againstk, with and withoutu?
Examples it will need¶
-
unicode_mode_dot_and_emoji_js.js— what ., .. and \p{RGI_Emoji} match in 😀 and 👨👩👧 with no flag, with u and with v -
unicode_mode_v_sets_js.js— the v flag's set difference and intersection tested on a handful of letters
See also¶
- Strings are UTF-16 — why . without u sees half an emoji
- Code points — code points, the unit that u makes . match
- Graphemes — what a reader calls one character, which even v cannot match in general
- Regex literals and flags — the other six flags
- Regex:
.— any character, except the ones it is not ↗ — what . matches in eight engines, emoji included - Regex:
\p{…}— a character by what it is, not what it looks like ↗ — \p{…} across engines, and JavaScript without u - Encodings: UTF-16 and surrogates ↗ — the surrogate pairs that . splits without u