Skip to content

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 /^.$/u say about "😀", and why?
  • How many . does 👨‍👩‍👧 take under u, and what matches it as one unit under v?
  • What does \p{L} mean without u, and what does it match with u?
  • What do the v flag's set operations do, such as [\p{L}--[a-z]] and &&?
  • Which escapes that pass without u become a SyntaxError with it, such as \a?
  • How does i treat the Kelvin sign (U+212A) against k, with and without u?

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

Sources to start from